Comments (5)
Thanks for calling this out, Johan. I agree the error message is not ideal, and that the additional information would be helpful, but unfortunately it looks like a fix is difficult to achieve. If it were possible at all it would imply significant changes and additions to the the template parsing code, with corresponding cost in perf, code size, and potentially stability of current code.
So my current take is that this is a 'won't fix`.
In fact the parsed code is view.ctxPrm("unknown")()
and the browser throws an error. For Chrome it is view.ctxPrm(...) is not a function. For Safari it is undefined is not a function... It would be nice if the browser gave the message view.ctxPrm("unknown") is not a function. But it doesn't, and we have no control over that...
from jsviews.
What I'm discovering is that I come back to a month old code or more and change something, perhaps a web api or something in a viewmodel which result in a template all of a sudden being linked against a new data structure. Bang I'm getting this kind of error. At best of times it's easy to find out which template expression is the culprit but it happens all to often that I have to remove a lot of template code and by process of elimination locate the template expression that is causing the error.
Perhaps a best effort would be enough. I'm noticing that the function buildCode(ast, tmpl, isLinkExpr)
is passed tmpl which contains the expression tmpl.markup
.
At the end of the function it builds up the dynamic javascript in the code
var such as this:
// unnamed
var v,ret=""
+((v=view.ctxPrm("unknown")())!=null?v:"");
return ret;
What if instead the dynamic javascript was generated something like this instead?
// unnamed
try {
var v,ret=""
+((v=view.ctxPrm("unknown")())!=null?v:"");
return ret;
} catch (err) {
err.message = "template: '" + tmplName + "', markup: '" + tmpl.markup + "' threw the following " + err.message;
throw err;
}
Instead of hijacking the error it might be better to throw a custom error. I seem to recall there being a template parser error..
This shouldn't incur any performance penalty, code size should be small and it would at least print out the template expression I should be looking out for.
from jsviews.
Ah - well if you want to include a try catch, I believe there is a perf cost, but you can do it with existing features. Just do the following, as an opt-in choice:
$.views.settings.debugMode(myOnErrorHandler);
function myOnErrorHandler(err, fallback, view) {
throw "template: '" + view.tmpl.tmplName + "', markup: '" + view.tmpl.markup + "' threw the following " + err.message;
}
(It is opt-in because of the trade-off perf/debugging information)
See https://www.jsviews.com/#onerror@debugmode-function.
You can also set onError on the tag, to pass in anything you want via the fallback parameter of your handler. It can be a string, an object or a function, such as the template object:
{{:~unknown() onError=#tmpl}}
function myOnErrorHandler(err, template, view) {
throw "template: '" + template.tmplName + "', markup: '" + template.markup + "' threw the following " + err.message;
}
from jsviews.
That first option does what I need. Thanks.
from jsviews.
Closing, since the requested feature is already available through existing feature: https://www.jsviews.com/#onerror@debugmode-function.
from jsviews.
Related Issues (20)
- How to observe property array properly? HOT 2
- observable ev.data.observeAll helper broken when path is "*" HOT 7
- linked tag property changed handler called when it shouldn't HOT 51
- {{for ..}} emits <tr> and <td> tags HOT 1
- for tag with range and data-linked tr give error when removing object from array HOT 5
- Delimiters not working for "[ " and " ]" HOT 2
- linking of selected value on select element does not work correctly with all jquery versions HOT 5
- jsrender.min.js.map truncated HOT 6
- Observable change error, when loading jquery.observable.js before jsrender.js, and using contextual parameters and sorted {{for}} HOT 6
- removeView performance HOT 2
- $.observe/$.unobserve performance degradation over time HOT 5
- If the selected value of a data-linked <select> is set prior to adding options, selection is not always established correctly HOT 3
- multiselect not updating when linked array changes HOT 10
- Binding to computed functions: onBind callback called twice. If computed function has no setter , "... is not a function" exception thrown HOT 6
- html comments not working in tables HOT 4
- performance improvement in JsObservable HOT 2
- Formatting a number in data-link ? HOT 2
- Using a tmpl selector that begins with a # but is not an ID selector does not work HOT 5
- Top-level data-link="{for...}" does not work on a 'select' element HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsviews.