Comments (8)
Yes .error()
is now broken because of course the external promise libraries are always going to call the reject
callback explicitly.
from bluebird.
Why does this fail? BB2.then shouldn't call reject.
Is it because BB.then calls reject if a rejected promise is returned ?
from bluebird.
@Raynos yeah I think the thing is that when assimilating an untrusted thenable, its impossible to differentiate between thrown errors (possibly even bugs) and rejections from BB.
What could be useful? To agree on a flag/convention that errors which have the flag isPromiseRejection = true
will be catched by .error()
and then tgriesser's create-error can be used to easily make and throw such errors. (or simply Bluebird.RejectionError)
Basically it comes down to this -- if library authors of libraries based on promises don't make a distinction, the distinction cannot be made. I think the best you can do in that case is to filter-out TypeError, ReferenceError, RangeError
as programmer errors and attach .isPromiseRejection = true
to every other kind of error (this would likely be better if opt-in and... I guess it could be done with functions like rejectify/rejectifyAll
over misbehaving promise-based libs -- or is that a horrible name? :D)
from bluebird.
@spion I don't understand how it's impossible. You mean a rejected thenable is impossible to differentiate from being rejected by reject(err)
or throw err
?
from bluebird.
@petkaantonov is it necessary that the same Error objects be used (with the global freeze) on all copies of the lib rather than providing them per-instance?
from bluebird.
@Raynos yes, and is also impossible to differentiate either from typo errors :|
And as we discussed it wouldn't matter even if reject(err)
were easy to differentiate from throw
, as most authors utilizing promises would simply throw their errors.
from bluebird.
@Raynos When assimilating thenable it will always call the reject callback, it will never throw, otherwise it wouldn't be a promise library. The reference error was already caught and turned into rejection in the other library long before even calling .cast
.
from bluebird.
For the record I'd just like to add that the behavior @spion describes is exactly what I expect when assimilating thenables from other libraries - and is in my opinion the expected behavior.
That said, I understand why it's not desirable and agree that it should be fixed.
What about giving all assimilated rejections a base type of AssimilatedRejectionError
and being able to catch that explicitly? That seems to both address the issue and not change current behavior.
var BB = require('bluebird');
var BB2 = require('bluebird/js/main/promise')();
BB.cast(1).then(function() {
return BB2.cast(1).then(function() {
return makes.reference.errors();
});
}).catch(BB.AssimilatedRejectionError,function(e){
// handle whatever
}).error(function(e) {
console.log("This should not execute", e);
});
We can also introduce a helper for this:
var BB = require('bluebird');
var BB2 = require('bluebird/js/main/promise')();
BB.cast(1).assimilateAsThrow().then(function() {
return BB2.cast(1).then(function() {
return makes.reference.errors();
});
}).error(function(e) {
console.log("This should not execute", e);
});
from bluebird.
Related Issues (20)
- Dead code in a function HOT 2
- UnhandledPromiseRejection(s) from .some, .any, etc HOT 1
- Minified version throws errors HOT 4
- Debugging is enabled by default HOT 1
- Travis-ci: builds are failing for node.js 0.10, 0.12,4,5 versions for AMD64 HOT 1
- `resolve` and `reject` returned from `.defer()` are not bound to `promise`
- Possibly a bug in OperationError wrapping
- CLS is sometimes lost when using cls-hooked without cls-bluebird
- Error finalising an async function promise => this._passThrough is not a function HOT 4
- Bluebird module generates output spam in npm v7 during installation HOT 2
- perhaps deprecate the npm package? HOT 6
- when i use npm test in this project ,i meet a error with `Error: jshint exited with code: 2`
- Please build and upload in npm new version HOT 2
- Certificate error for bluebird documentation site
- Feature: use ES6 proxy to support all methods on promised objects HOT 1
- Documented installation method doesn't work with Node 18 HOT 2
- "Cannot promisify an API that has normal methods with 'Async'-suffix\n\n See http://goo.gl/MqrFmX\n
- Vulnerable to memory leak HOT 1
- How to enable cancellation correctly? HOT 1
- Vulnerable dependencies (indirect security issues) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bluebird.