Skip to content

Show the template's line for syntax errors compiled through Herb - #59602

Merged
byroot merged 1 commit into
rails:mainfrom
IslamElsayed:herb-syntax-error-template-line
Nov 5, 2026
Merged

byroot merged 1 commit into
rails:mainfrom
IslamElsayed:herb-syntax-error-template-line

Conversation

@IslamElsayed

Copy link
Copy Markdown
Contributor

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#call doesn'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 in SyntaxErrorProxy highlights the right line. Nothing is re-parsed.

FakeTemplate in dependency_tracker_test.rb gains an identifier, 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

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Drafted with Claude Code; reviewed by @IslamElsayed.

🤖 Generated with Claude Code

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
byroot force-pushed the herb-syntax-error-template-line branch from 56cb994 to 4927ac6 Compare November 5, 2026 09:21
@byroot
byroot merged commit 13b5592 into rails:main Nov 5, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants