Skip to content

fix: improve error messages for invalid template tags in HTML start tags#499

Closed
dupontbertrand wants to merge 2 commits intometeor:release-3.1.0from
dupontbertrand:fix/better-attribute-block-errors
Closed

fix: improve error messages for invalid template tags in HTML start tags#499
dupontbertrand wants to merge 2 commits intometeor:release-3.1.0from
dupontbertrand:fix/better-attribute-block-errors

Conversation

@dupontbertrand
Copy link
Copy Markdown

@dupontbertrand dupontbertrand commented Apr 3, 2026

Summary

  • The pattern <input {{#if isDisabled}}disabled{{/if}}> causes a silent compiler crash with a misleading error: Cannot find module '../.././imports/ui/.../template.html' and Template.xxx is not defined. Developers waste hours debugging a module resolution issue that is actually a Spacebars syntax problem.
  • This PR replaces the cryptic failure with specific, actionable error messages for each invalid pattern:
    • {{#if}}/{{#unless}}/{{#each}}/{{#with}} in start tag: suggests the attribute="{{helper}}" pattern with Bad/Good syntax example
    • {{{triple-stache}}} in start tag: explains the raw HTML issue
    • {{> inclusion}} in start tag: clear rejection message
    • Custom block helpers: specific message mentioning dictionary helpers
  • Add test coverage with string assertions for each error path

Before

Cannot find module '../.././imports/ui/pages/myPage/template.html'
Template.myTemplate is not defined

After

{{#if}} is not allowed in an HTML start tag. To conditionally add a boolean
attribute like "disabled", "checked", or "selected", use the
attribute="{{helper}}" syntax instead.
  Bad syntax:  <input {{#if isDisabled}}disabled{{/if}}>
  Good syntax: <input disabled="{{isDisabled}}">

Test plan

  • Tested manually with a Meteor 3.4 app using local package symlinks
  • Verified {{#if}} standalone attribute shows new message with Bad/Good example
  • Verified {{{triple-stache}}} in start tag shows raw HTML message
  • Verified {{> inclusion}} in start tag shows inclusion message
  • Verified valid case ({{#if}} inside attribute value) still compiles and runs
  • Tinytest suite (spacebars-compiler - parse) passes — 416/416 tests, 0 failures

Replace the generic "Reactive HTML attributes must either have a constant name..."
message with specific, actionable errors for each case:
- {{#if}}/{{#unless}} in start tag: suggests attribute="{{helper}}" pattern
- {{{triple-stache}}} in start tag: explains raw HTML issue
- {{> inclusion}} in start tag: mentions it's not allowed
- Custom block helpers: clear rejection message
Switch from regex to string substring matching for test.throws
assertions, which is more reliable across Tinytest versions.
@jankapunkt jankapunkt added this to the 3.1 milestone Apr 8, 2026
@jankapunkt
Copy link
Copy Markdown
Collaborator

@dupontbertrand @wreiske can you please check if this may conflict with pr #481

@wreiske
Copy link
Copy Markdown
Contributor

wreiske commented Apr 8, 2026

I believe #481 does cover this use case, yes.

Screenshot 2026-04-08 at 9 02 36 AM

@dupontbertrand
Copy link
Copy Markdown
Author

My bad, don't know something like that was already there ! @wreiske @jankapunkt

@wreiske
Copy link
Copy Markdown
Contributor

wreiske commented Apr 8, 2026

No worries at all! It shows that multiple people thought it needed improvement so there's some validation there! ☺️

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.

3 participants