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

Error when passing an argument to a non-existing template helper #4230

Closed
mitar opened this issue Apr 17, 2015 · 4 comments
Closed

Error when passing an argument to a non-existing template helper #4230

mitar opened this issue Apr 17, 2015 · 4 comments

Comments

@mitar
Copy link
Contributor

mitar commented Apr 17, 2015

There is big difference between:

{{foo.bar}}

And:

{{foo.bar 'test'}}

When foo does not even exist as a template helper/in data context.

The first one does not return anything, the second one throws Uncaught Error: Can't call non-function: null (it is not even captures by Blaze).

I think none of those should throw an error (or there should be a debug switch for all of missing template helpers to throw an error). There is no much difference between calling foo.bar() and foo.bar('test') in my opinion.

I would really love if spacebars would work like CoffeeScript. That this would be foo?.bar 'test'. So if foo does not exist, it should simply not continue.

Now I have to make for each such case a helper, which does foo?.bar for me. Or wrap the thing into {{#if foo}}...{{/if}}.

@glasser
Copy link
Contributor

glasser commented Apr 21, 2015

Thanks for the feature request! We welcome discussions about how to make Meteor better. If you haven't yet, check out our wiki page about feature requests on GitHub.

This is working as intended, but we could relax the error if there is strong agreement that the "I said there was going to be a function but there wasn't but who cares" semantics is better.

@mitar
Copy link
Contributor Author

mitar commented Apr 22, 2015

Maybe I am just used to it from Django. The issue is that this can break at runtime into end-users faces.

I do not think there can be a strong agreement though. This is like strict vs. dynamic type checking debate. It depends on the taste. :-) Maybe the difference could be that in production it does not blow up, during development it does.

@mitar
Copy link
Contributor Author

mitar commented Apr 22, 2015

The issue is that you cannot really "catch" those errors and display something else instead. Or suppress it. That could be also one option. That you could register a template rendering error handler and decide in there what to do. You could return another template to render. Or you could just rethrow.

@hwillson
Copy link
Contributor

This issue has been moved to meteor/blaze#217 - closing here. Thanks!

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

No branches or pull requests

4 participants