Repository navigation
Show the template's line for syntax errors compiled through Herb - #59602
Merged
Merged
Conversation
Herb reports the line of a syntax error, but the ERB handler never told it which file it was compiling, so its errors said `[source]:4:6`. Rails can't resolve that path, so the error page showed Herb's own source instead of the template. Pass the template's identifier as `:filename`. The existing trace parsing then finds the right file and line. Ref rails#51092
byroot
force-pushed
the
herb-syntax-error-template-line
branch
from
November 5, 2026 09:21
56cb994 to
4927ac6
Compare
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This Pull Request has been created because the error page shows the wrong source for syntax errors in templates compiled through Herb, the default for HTML templates under
load_defaults 8.2. This is part of #51092.Herb finds the correct line, but
ActionView::Template::Handlers::ERB#calldoesn't pass it a filename, so the error reads[source]:4:6. Rails can't resolve that path, so for a stray<% end %>on line 4 the page shows Herb's own source ("around line #412") instead of the template.Detail
This Pull Request changes the ERB handler to pass
filename: template.identifier. The error then names the template, and the existing parsing inSyntaxErrorProxyhighlights the right line. Nothing is re-parsed.FakeTemplateindependency_tracker_test.rbgains anidentifier, because it goes through this handler.Additional information
This doesn't fix Erubi, which still compiles non-HTML formats and apps on older defaults. There, Ruby often only notices the mistake at the end of the method compiled around the template, so it reports a line past the end of the file. That's why this references #51092 rather than closing it.
Tested on Ruby 3.4.7 with Prism and parse.y, using the locked Herb 0.11.0. Herb 0.10, which the gemspec also allows, is untested.
Checklist
[Fix #issue-number]Drafted with Claude Code; reviewed by @IslamElsayed.
🤖 Generated with Claude Code