whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
7.99k stars 2.61k forks source link

onerror and onunhandledrejection/onrejectionhandled could use some nice developer-friendly examples #676

Open domenic opened 8 years ago

domenic commented 8 years ago

I notice that these features aren't really summarized anywhere developer-readable.

This is kind of a good first bug. Coming up with nice examples is an art. For promise rejection events, you can draw inspiration from https://nodejs.org/api/process.html#process_event_unhandledrejection. In all cases, I think it would be ideal to show use of something like navigator.sendBeacon for reporting the errors to the server.

I intend to work on this soon unless someone else volunteers. When that happens I'll update the assignee to myself and remove "good first bug". In the meantime, community members should feel free to use the comments to submit small examples that illustrate good production uses of these events.

kriskowal commented 8 years ago

I did a prototype of a Chrome inspector panel for Q based on hooks for "defer", "progress", "resolve", "unhandled rejection", and "rejection handled" messages.

https://github.com/montagejs/continuum

There is a video demonstrating that these hooks are sufficient to create an inspector suitable for casually discovering "forever pending" promises as well as "never handled" rejections (for intuitive values of "forever" and "never").

This PR to Q would have introduced the necessary hooks. Watch for calls to the "debug" function.

https://github.com/kriskowal/q/pull/361/files

If I were to revisit this idea, it would be to provide Q.onevent hooks that an external library could hook up for each of these cases, sending messages to a tracing backend or inspector panel extension via window message passing.

domenic commented 1 month ago

In https://github.com/whatwg/html/pull/10550#discussion_r1706166364 @jeremyroman notes that we should not just add clarifying web-developer-facing examples. We should also explain the setup for implementers. There are enough moving pieces that it's confusing: the outstanding rejected promises weak set, the about-to-be-notified rejected promises list, the HostPromiseRejectionTracker abstract op, and the notify about rejected promises algorithm. What they're all working to accomplish can be hard to understand, so explaining the moving pieces alongside any examples we introduce would be good.