-
Notifications
You must be signed in to change notification settings - Fork 408
onHandleError is sometimes triggered for handled Bluebird rejections #1119
Description
- Zone.js 0.8.26
- Bluebird 3.5.0
- Chrome 67
onHandledError is sometimes called for handled rejections when using the Zone.js Bluebird patch.
In this example, onHandleError is called despite catch. The catch callback itself is not called.
const Bluebird = require("bluebird");
require("zone.js");
require("zone.js/dist/zone-bluebird");
Zone[Zone["__symbol__"]("bluebird")](Bluebird);
const zone = Zone.current
.fork({
name: "testErrorHandling",
onHandleError(a, b, c, err) {
console.log("onHandleError caught: " + err);
}
})
zone.runGuarded(() => {
return Bluebird.resolve()
.then(() => {
throw new Error("test error");
})
.catch(() => {
// never invoked
console.log("caught");
});
});If the runGuarded callback calls Bluebird.reject instead, we get the expected behaviour: the catch callback is called, onHandleError is not.
zone.runGuarded(() => {
return Bluebird.reject(new Error("test error"))
.catch(() => {
// this time it is invoked
console.log("caught");
});
});
If global.Promise is patched before the Zone.js Bluebird patch we get the expected behaviour in both examples, whether we use Bluebird or Promise.
const Bluebird = require("bluebird");
global.Promise = Bluebird;
require("zone.js");
require("zone.js/dist/zone-bluebird");
Zone[Zone["__symbol__"]("bluebird")](Bluebird);
If global.Promise is patched after the Zone.js Bluebird patch, the Promise.reject example invokes the catch callback as expected. However, in the Promise.resolve example, even the .then callback is not called. No error is thrown, and onHandleError is not invoked.
const Bluebird = require("bluebird");
require("zone.js");
require("zone.js/dist/zone-bluebird");
Zone[Zone["__symbol__"]("bluebird")](Bluebird);
global.Promise = Bluebird;
// same ZoneSpec as above...
zone.runGuarded(() => {
return Promise.resolve()
.then(() => {
// never executed!
throw new Error("never happens")
})
.catch(() => {
// never called
})
});I think this last one may be incorrect usage, but I couldn't confirm that from the docs.