Giter VIP home page Giter VIP logo

Comments (8)

petkaantonov avatar petkaantonov commented on May 18, 2024

Yes .error() is now broken because of course the external promise libraries are always going to call the reject callback explicitly.

from bluebird.

Raynos avatar Raynos commented on May 18, 2024

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.

spion avatar spion commented on May 18, 2024

@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.

Raynos avatar Raynos commented on May 18, 2024

@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.

tgriesser avatar tgriesser commented on May 18, 2024

@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.

spion avatar spion commented on May 18, 2024

@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.

petkaantonov avatar petkaantonov commented on May 18, 2024

@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.

benjamingr avatar benjamingr commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.