Skip to content

Preserve Writer failures when a template starts at column zero - #1197

Open
allenflux wants to merge 1 commit into
jknack:masterfrom
allenflux:allenflux/fix-render-error-column
Open

allenflux wants to merge 1 commit into
jknack:masterfrom
allenflux:allenflux/fix-render-error-column

Conversation

@allenflux

Copy link
Copy Markdown

When a Writer fails while rendering text at the start of a line, the zero-based template column is passed to HandlebarsError, which requires a positive column. The resulting IllegalArgumentException hides the original write failure reported in #1070.

Normalize the diagnostic column to at least 1, matching HbsErrorReporter, and use it in both the error object and message header. This preserves the original exception as the cause of HandlebarsException without changing Template.position() or positive column values.

One regression test uses a Writer that throws an IOException on the first text write. It fails on the original implementation and passes with this change, checking that the original cause is preserved and the diagnostic column is 1.

Validation on Temurin 21 (Java 17 compilation target):

  • mvn -pl handlebars -am test: 1,039 tests, zero failures/errors, 3 existing skips. The baseline ran 1,038 tests with the same skips.
  • Spotless check for the two changed files and git diff --check passed.

Fixes #1070.

Implemented with assistance from OpenAI Codex.

@allenflux
allenflux marked this pull request as ready for review October 14, 2026 05:14
@jknack jknack added this to the 4.5.6 milestone Oct 16, 2026
@jknack jknack added the bug label Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected IllegalArgumentException using an inline template and a custom Writer

2 participants