dustjs icon indicating copy to clipboard operation
dustjs copied to clipboard

2.7.5: "Context.prototype._get" prints wrong error when property/reference not found in context; should throw error, not only log

Open thomas-mindruptive opened this issue 8 years ago • 5 comments

nodejs 7.4.0 dustjs 2.7.5

Template "article.html":

<head>
    {>html-head/}
    <meta name="keywords" content="{properties.category-x}">
    <meta name="author" content="{properties.author}">
</head>

The property "properties.category-x" does not exist in the given context. So the error is in template "article.html" but dust says: "Cannot find reference {properties.category-x} in template html-head". So maybe dust uses the latest context (html-head partial) instead of the current one? This makes it very hard to pin down errors in case of may templates.

  1. dustjs swallows the missing reference, it just logs it in "Context.prototype._get". This is very error prone and makes errors hard to find. A missing property is usually a typo or other error in the template. Could you add an option to dustjs to throw an error in such a case?

Thanks a lot Tom

thomas-mindruptive avatar Mar 12 '17 15:03 thomas-mindruptive

Likely related to #755

jimmyhchan avatar Mar 12 '17 17:03 jimmyhchan

Thanks, exactly! The second issue: Is it possible to add an option to throw errors when properties are not found in the context, e.g. "{properties.category-x}". Thanks

thomas-mindruptive avatar Mar 12 '17 17:03 thomas-mindruptive

Hi, I just wanted to follow up with @jimmyhchan to ask if there are any plans to add the option to throw an error in case of a property not found in context. I would really help to build more reliable templates because a missing property usually means an error or typo in the template. Otherwise you miss a lot of potential problems during build-time. Thanks a lot Thomas

thomas-mindruptive avatar Mar 31 '17 13:03 thomas-mindruptive

Are there any news on this topic? Thanks a lot!

thomas-mindruptive avatar Sep 09 '17 15:09 thomas-mindruptive

see this comment https://github.com/linkedin/dustjs/issues/757#issuecomment-327928472

jimmyhchan avatar Sep 11 '17 21:09 jimmyhchan