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

Catch syntax errors in context and fail gracefully #495

Merged
merged 3 commits into from
Sep 6, 2014

Conversation

sethkinast
Copy link
Contributor

Reviving #267 with un-bitrotted code.

This catches three cases where errors in context functions would bomb execution:

  1. _get would try to execute functions from the context. If they fail, it return dust.log(), which returns undefined.
  2. map() would try to execute a callback, but the callback could throw.
  3. sections can be functions that are executed, but the functions could throw.

All of these now log an ERROR level, and call setError() on their chunk.

The easiest way to see the effect is to introduce a syntax error into one of the test cases. The dust.render() callback will never be invoked, which cripples many Node-based implementations that use Dust rendering, since they just spin forever.

I did introduce another change in this PR: if tests are expecting an error, they now pass if the expected value is contained within the error, instead of checking equality. This is because PhantomJS has different errors compared to a browser.

Seth Kinast added 2 commits September 2, 2014 15:47
…f error messages.

This allows tests that throw different errors in PhantomJS vs a browser to pick a commonality and test on that instead of the exact error message.
@sixlettervariables
Copy link

+1, I had wondered why my Dust templates sometimes hung (node v0.10).

@prashn64
Copy link
Contributor

prashn64 commented Sep 5, 2014

lgtm, one more set of eyes.

@rragan
Copy link
Contributor

rragan commented Sep 5, 2014

lgtm

prashn64 added a commit that referenced this pull request Sep 6, 2014
Catch syntax errors in context and fail gracefully
@prashn64 prashn64 merged commit d2e2a85 into linkedin:master Sep 6, 2014
@sethkinast sethkinast deleted the catch-helper-errors branch September 6, 2014 01:08
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.

4 participants