Better error handling options #66

bakesteve opened this Issue Feb 8, 2011 · 3 comments


None yet
3 participants

Lookups fail silently - optionally throw / return.
Would be nice to be able to optionally set a template to throw back any lookup failures ( == undefined)
Or, possible have some form of error stack we can then access once the template has run?
Would make unit testing much much easier, as then all I need to do is mock an object and assert / check error object.
Know this was originally discussed:
but cant see that it went anywhere.


BorisMoore commented Feb 8, 2011

Yes, this is on our list of features we are considering...

See also




Had a look at doing this and for our internal testing code, have added in the following code.
I modified the data item bind template code, and keep an array of errors within the generated template function. For now, I'm using a custom event trigger to pass the error data out - although given there is no meaningful element to trigger this off it seems strange so maybe better to raise an event from the template item, or a global tmpl event - (jQuery.tmpl.templateError?) - something similer to the tmplPlus rendered event perhaps?

This fits our needs, and think should work for others scenarios. For other errors (missing nested templates, etc) should be simple to just add to the _error collection, and maybe extend the object (at the moment just Id and Message) to have a type or some identifier? perhaps the tmpl tag? Let me know your thoughts

the changes are:
line 241:
open: "if($notnull_1){__.push($.encode($1a));}" + "else{_errors.push({Id:'$1',Message:'Property not found'});}"

line 320:
"var _error=[];" +

line 359:
"');} if(_errors.length>0){$(document).trigger('tmpl.error',_errors);} return __;"


rdworth commented Oct 8, 2011

Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment