jsrender error handling approach #134

Closed
jaxley opened this Issue Jun 12, 2012 · 4 comments

Projects

None yet

3 participants

@jaxley
jaxley commented Jun 12, 2012

We're using jsrender inside jquerymx views as a view engine and need to hook into the jsrender error conditions in order to bubble those errors up into higher layers to fire appropriate callbacks. e.g. if jsrender couldn't find a template or if jsrender couldn't parse the template or if jsrender couldn't render the template because the data passed in had some problem matching to the template, a helper function is not defined or has an error in it, etc.

I haven't seen examples of doing this -- is there anything documented or any examples of how to hook into those issues to be able to take action, such as render alternate error content or retry?

@jeffrose

Agreed. The ability to hook into the jsrender error handling would be useful.

@BorisMoore
Owner

This request has been addressed (or at least much improved) in the latest commit (19). Error handling has been much improved (with better support for clear error messages when you make syntax errors in the template etc.). There is now a custom error type which you can catch in your code, and you can also override that Error type by replacing $.views.Error by a different implementation - in which you can add your own hooks.

You can set $.views.debugMode to false is you want to suppress the throwing of exceptions on error (and hide error messages from the user).

However, some scenarios will not throw - specifically if a data property or helper/template parameter whose value is being rendered is undefined, since JsRender deliberately supports 'jagged data' - and renders the empty string when the value is undefined.

Leaving this open until you have been able to test this design and implementation...

@jeffrose
jeffrose commented Jul 6, 2012

Thanks. I will try this out next week and let you know.

@BorisMoore
Owner

Closing, since I didn't hear back.

@BorisMoore BorisMoore closed this Aug 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment