Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PromiseRejectionEvent differs from Living Standard spec #1447

Closed
abirmingham opened this issue Sep 7, 2017 · 13 comments
Closed

PromiseRejectionEvent differs from Living Standard spec #1447

abirmingham opened this issue Sep 7, 2017 · 13 comments

Comments

@abirmingham
Copy link

  1. What version of bluebird is the issue happening on?
    3.5.0

  2. What platform and version? (For example Node.js 0.12 or Google Chrome 32)
    Google Chrome 56.0

  3. Did this issue happen with earlier version of bluebird?
    Yes.

Bluebird seems to be creating a PromiseRejectionEvent with a 'detail' property, which contains 'promise' and 'reason' properties. TypeScript complains that PromiseRejectionEvent has no 'detail' property, which prompted me to look at the specification for this event. It appears that 'promise' and 'reason' are intended to be properties of the event object itself, e.g. event.promise and event.reason.

Perhaps I'm missing something?

Spec info found here -
https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent/PromiseRejectionEvent
https://html.spec.whatwg.org/multipage/webappapis.html#promiserejectionevent

@benjamingr
Copy link
Collaborator

Bluebird fired these events for several years before browsers specified them so it uses a version that predates what the DOM settled on.

Note that you can use onPossiblyUnhandledRejection on the library itself and re-emit the events as you see fit if you'd like.

@abirmingham
Copy link
Author

That makes sense! Thanks for the explanation.

Now that a standard has been defined, shouldn't bluebird adhere to it? It seems like it would be worth the breaking change as part of a major release.

@petkaantonov
Copy link
Owner

It can be done in backwards compatible way

@nornagon
Copy link
Contributor

nornagon commented Oct 5, 2017

Bugsnag was having trouble picking up on Bluebird's unhandled rejection messages (see https://github.com/bugsnag/bugsnag-js/blob/master/src/bugsnag.js#L1285), hopefully #1464 fixes this!

@benjamingr
Copy link
Collaborator

PR LGTM, @domenic can you please take a look and confirm this is compatible with the standard?

@domenic
Copy link

domenic commented Oct 5, 2017

I mean it's not exactly an implemenation of it, and differs in little ways (e.g. getter vs. data property) but if the goal is to be able to write code that works roughly the same in both, adding promise and reason properties to the event object seems reasonable.

@benjamingr
Copy link
Collaborator

I mean it's not exactly an implemenation of it, and differs in little ways (e.g. getter vs. data property) but if the goal is to be able to write code that works roughly the same in both, adding promise and reason properties to the event object seems reasonable.

If we're doing this (which I think we should to ensure an easy transition from/to bluebird) I think we should actually implement the differences. Is there anything we can test against? (as in, are there tests for how the event is fired we can make sure we pass?)

@nornagon would you be willing to change the code to getters?

@nornagon
Copy link
Contributor

nornagon commented Oct 5, 2017

See #1464 (comment), would that be a better way of implementing this?

@nornagon
Copy link
Contributor

nornagon commented Oct 5, 2017

Updated the PR to use getters.

@domenic
Copy link

domenic commented Oct 6, 2017

I think we should actually implement the differences

I don't feel that's realistic for a Node.js API? E.g. there's no Event class in Node.js, so you'll have to implement that whole hierarchy. Then you'll have to get rid of the detail property you're currently using. There's a lot more...

(as in, are there tests for how the event is fired we can make sure we pass?)

The tests were largely derived from the Node.js tests, but they live at https://github.com/w3c/web-platform-tests/tree/master/html/webappapis/scripting/processing-model-2/unhandled-promise-rejections

brenthompson added a commit to brenthompson/electron-unhandled that referenced this issue Apr 9, 2018
Bluebird.js promises don't have event.reason, they instead have event.detail.reason. An unhanded rejection from bb causes an exception from your plugin. Given Bluebird's popularity it's probably worthwhile handing this case at least until they fix their side. As you can see they've taken a couple of kicks at this already. Links to their issues:
petkaantonov/bluebird#1447
petkaantonov/bluebird#1509
@elad-maimon
Copy link

Hello,

Why was this issue closed?
The suggestion above of using onPossiblyUnhandledRejection doesn't seem to be aligned with documentation that says

this hook is specific to the bluebird instance its called on, application developers should use global rejection events

Also, typescript would not allow solutions like that one that was mentioned above, unless we have some type to define the event that bluebird fires (searched in DefinitelyTyped and couldn't find).

IMHO Bluebird should be aligned with the spec and trigger the event with PromiseRejectionEvent instance, for now, if there's type definition it could be really helpful.

Thanks!

@benjamingr
Copy link
Collaborator

benjamingr commented Jul 23, 2019

IMHO Bluebird should be aligned with the spec and trigger the event with PromiseRejectionEvent instance, for now, if there's type definition it could be really helpful.

The local unhandled rejection events and the global ones are separate and solve separate things.

The last batch of differences was fixed in 8991667

This issue is misleading because it broke again before it was fixed.

@benjamingr
Copy link
Collaborator

It's possible we haven't had a release with this yet because of the async_hook fears. @petkaantonov ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants