Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If helper can generate several syntax errors that aren't very useful #1548

Closed
ErisDS opened this issue Sep 9, 2019 · 2 comments
Closed

If helper can generate several syntax errors that aren't very useful #1548

ErisDS opened this issue Sep 9, 2019 · 2 comments

Comments

@ErisDS
Copy link
Collaborator

ErisDS commented Sep 9, 2019

If you write a malformed {{#if}} helper with too many arguments, you get weird syntax errors that are different depending on just how you malformed the helper:

{{#if anything_goes_here "string"}}

cannot read property 'includeZero' of undefined

{{#if anything_goes_here undefined}}

Cannot read property 'hash' of undefined

{{#if anything_goes_here null}}

Cannot read property 'hash' of null

Here's a JS Fiddle demonstrating these errors
https://jsfiddle.net/m5a9q3b0/3/

Obviously, the if statement examples are incorrect, but the varied weird errors that get generated are the problem. In Ghost themes we regularly see all 3 of these errors, and it's clear noone understands what they mean or how to fix them.

We just added an ugly workaround to Ghost you can see here

ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Sep 9, 2019
fixes handlebars-lang#1548

- add a guard to show readable syntax error for if / unless helper
- prevents against 3 different errors that can be generated by different systax errors
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Sep 9, 2019
fixes handlebars-lang#1548

- add a guard to show readable syntax error for if / unless helper
- prevents against 3 different errors that can be generated by different systax errors
@nknapp
Copy link
Collaborator

nknapp commented Sep 9, 2019

related to #1549

ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
fixes handlebars-lang#1548

- add a guard to show readable syntax error for if / unless helper
- prevents against 3 different errors that can be generated by different systax errors
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
fixes handlebars-lang#1548

- add a guard to show readable syntax error for if / unless helper
- prevents against 3 different errors that can be generated by different systax errors
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
fixes handlebars-lang#1548

- add a guard to show readable syntax error for if / unless helper
- prevents against 3 different errors that can be generated by different systax errors
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
ErisDS added a commit to ErisDS/handlebars.js that referenced this issue Oct 25, 2019
fixes handlebars-lang#1548

- add a guard to show readable syntax error for if / unless helper
- prevents against 3 different errors that can be generated by different systax errors
@nknapp nknapp closed this as completed in c76ded8 Oct 27, 2019
@nknapp
Copy link
Collaborator

nknapp commented Oct 28, 2019

Released in 4.5.0

ErisDS added a commit to TryGhost/Ghost that referenced this issue Nov 25, 2021
refs: #10496
refs: handlebars-lang/handlebars.js#1548

- For a while, handlebars would and could generate quite a lot of obscure sytnax error messages for malformed helpers that we couldn't catch in gscan
- This was fixed in handlebars-lang/handlebars.js#1548
- We have also since added AST parsing to gscan, so if there are more obscure syntax errors, we should be able to add rules to catch them
- Therefore, this additional, overly specific code block isn't needed anymore, so let's clean it up!
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

No branches or pull requests

2 participants