-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$q: Rejected Promises with non rejection callback should report the rejection reason in the console. #13653
Comments
I guess this logging comes at a price, because it needs |
I think there are two sides here:
I find the current behavior of (1) to be the correct one, an exception was thrown and it should be reported (maybe should be configurable?). The current behavior of (2) is open to discussion; If this is implemented, then when a promise is rejected we may over-trigger as we are not sure if the user will call |
@lgalfaso I agree with you, and we can deal with (2) to our expectation too Promise.resolve(0).then(function(){
return Promise.reject(5)
}).catch(alert) But the below will report the rejection Promise.resolve(0).then(function(){
return Promise.reject(5)
}) I have implemented the Promise once, and as I know, the promise's handler function(s) will always run in async mode, which means we can report the error in the Promise.resolve(0).then(function(){
var promise2
return promise2 = Promise.reject(5)
}).catch(alert) the I think $q can do the same thing to achieve the goal. |
I think it is possible have something that behaves like this. I think it will take some extra work as we would need to do some changes to |
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Created #13662 that implements this. The change is somehow larger than what I was expecting it to be, but should be good to continue the discussion over there. |
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Unhandled rejected promises will be logged to $exceptionHandler. Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Unhandled rejected promises will be logged to $exceptionHandler. Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Rejected promises that do not have a callback to handle the rejection report this to $exceptionHandler so they can be logged to the console. BREAKING CHANGE Unhandled rejected promises will be logged to $exceptionHandler. Tests that depend on specific order or number of messages in $exceptionHandler will need to handle rejected promises report. Closes: angular#13653 Closes: angular#7992
Eg: If I write the code below:
Notice the
alter
(should bealert
) function which is not exist and will cause an error which will be caught and adopted by the promise returned by the last then which is thepromise2
.If you run this code in console, you'll see something like
Uncaught (in promise) ReferenceError: alter is not defined(…)
in console.The primitive Promise in ES6 will report rejected reason in console when the promise has no rejection handler.
But if you change the
Promise
to$q
in the above code snippet, you won't see the error reported in console. Which is bacsuse $q did not do this.Sometimes if the promise returned by the last
then
method in promise chain and something went wrong in the lastthen
method, the promise will got rejected, if the promise implementation do not report the error in the console, the developers would never know the error unless he/she dive deep in the code...On the contrary, Q's
done
method can report the error(but if you don't chain adone
method in the promise chain, it won't), and Bluebird will always report the error(and some useful warnings) in console if a rejected promise has no rejection handler.Q(notice the

done
method):Bluebird(with warnings):

$q(do not report error on rejected promise):

$q(always report):

Eh...as I wrote this, I found that since angular 1.4.x, it starts to report the error or exception caught in the promise but even if the exception will be processed in the subsequent promise chain, it still report the error which is not a desired behavior:

What is thought to be the desired behavior is that it only report rejected promises' errors when there is no rejection handler registered on the promise(that is, never called
then(*,handler)
on it), which is like Q or Bluebird or ES6 primitive Promise.The text was updated successfully, but these errors were encountered: