Skip to content

fix: cap oversized header/footer instead of throwing#24

Closed
wnbsmart wants to merge 1 commit intomasterfrom
fix/cap-oversized-header-footer
Closed

fix: cap oversized header/footer instead of throwing#24
wnbsmart wants to merge 1 commit intomasterfrom
fix/cap-oversized-header-footer

Conversation

@wnbsmart
Copy link
Copy Markdown

@wnbsmart wnbsmart commented Apr 1, 2026

Summary

  • When header + footer heights exceed the available page space, proportionally scales them down instead of throwing Header/footer too big error
  • Fixes a production bug where proposals with large document styles (header 274px + footer 701px on an 842px A4 page) crashed PDF generation entirely
  • Capped settings flow through the entire pipeline — section PDFs render at capped heights, clipping excess content while producing a valid PDF

Context

  • Productive task: #18171
  • API Bugsnag: OpenURI::HTTPError: 500 Internal Server Error in proposals/proposals#send_mail
  • Exporter Bugsnag: Error: Header/footer too big. Page height: 842px, header: 274px, footer: 701px, body: -131px
  • Affected customer: org 52710 (29E6), proposal 11951

How it works

capOversizedSections() in createPageLayoutSettings detects when headerHeight + footerHeight > pageHeight * (1 - bodyHeightMinimumFactor) and applies a proportional scale factor to all header/footer section settings. The capped settings are cloned (original settings are not mutated) and passed through to calculatePageLayout and downstream rendering.

The internal calculatePageLayout validation is preserved as-is — it still throws if called directly with invalid values, maintaining the library's invariants.

Test plan

  • Existing 16 layout tests pass unchanged
  • 5 new tests covering: real-world A4 reproduction, no-op for fitting sections, multi-variant capping, page number preservation, background height preservation
  • Full test suite (124 tests) passes
  • Lint passes

🤖 Generated with Claude Code

When header + footer heights exceed the available page space (leaving
less than bodyHeightMinimumFactor for the body), proportionally reduce
all section setting heights to fit. Previously this threw an error
crashing the entire PDF generation.

Real-world case: A4 page (842px) with header 274px + footer 701px
produced negative body height (-131px) and threw "Header/footer too big".
Now sections are scaled down proportionally, clipping excess content
while still producing a valid PDF.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wnbsmart wnbsmart closed this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant