-
Notifications
You must be signed in to change notification settings - Fork 27.4k
'undefined is not a function' when promise function not defined #11330
Comments
That is because the See function hoisting vs var hoisting. |
@jbedard is right. Closing as not a valid issue |
The problem is that the error is not nice at all and since it's thrown usually asynchronously with respect to where the callback was registered, it's really hard to debug. Could we just silently ignore, if the callback is not a function? Would this break Promises A+ spec? a little bit more context: https://twitter.com/olore/status/577277479506837504 |
OK, so this is hard to debug but it is a JS development error not a failure in Angular. Wherever there is code that takes a callback, you have to have defined the callback before you pass it to the code. Silently ignoring if the callback is not a function will make this even more difficult to debug! There won't even be an error but the error callback will silently not be called if the HTTP request errors. I think we could throw an error if you call |
I created a PR with this in mind. @olore and @IgorMinar is this an acceptable fix? Now if you fail to pass in a valid function to either |
I think this will give more clarity to the situation. |
So, if we want to keep those callbacks close to promises callbacks we should ignore non-function arguments: https://promisesaplus.com/#point-23 |
The only reason the promise spec allows us to ignore params is because they are all optional but I am pretty sure that passing no parameters is always an error. In the case of |
Well, the spec says "if it is not a function", so I'm not sure it is only about optional params |
…ve a function Closes angular#11330 Closes angular#11333
Guys thanks for seeing this one through. |
…ve a function Closes angular#11330 Closes angular#11333
Using 1.4.0-beta.5, the following stack trace seems to be the result of an error() function not being defined during promise rejection. The rejection still bubbles up, however the "undefined is not a function" is logged in the console.
http://plnkr.co/edit/JtaNeNEcxFLPH5ByuHI8
The text was updated successfully, but these errors were encountered: