html icon indicating copy to clipboard operation
html copied to clipboard

Copy over the error from inside workers to the Worker error event?

Open domenic opened this issue 3 years ago • 3 comments

When an uncaught exception occurs inside a worker, it fires:

  • An ErrorEvent "inside", on the WorkerGlobalScope object. The event.error property contains the exception value.

  • An ErrorEvent "outside", on the Worker object. The event.error property is null.

(Relevant spec section)

This made sense, back before we had a way to serialize exceptions across thread boundaries. However, https://github.com/whatwg/html/pull/4665 introduced that ability! So maybe we should consider setting the "outside" error property to a clone of the "inside" error property?

IMO this has a few prerequisites before I'd be fully comfortable with it:

  • Figure out the interop issues mentioned in https://github.com/whatwg/html/issues/2289. That is mostly about the error event fired during Worker initialization, which uses (per spec at least) Event instead of ErrorEvent, but interop issues in this area make me nervous about adding more.
  • Try to get error serialization itself on better footing, per the stalled https://github.com/whatwg/html/pull/5749. /cc @syg @evilpie

domenic avatar Feb 09 '22 19:02 domenic

cc @asutherland

annevk avatar Feb 15 '22 12:02 annevk

This definitely seems reasonable given the new serialization support. Thank you!

Offtopic-ish Aside: It might also be nice to consider improving the ergonomics around unhandledrejection so that they also could propagate to the Worker binding. I feel like the last time I looked at this it was necessary to add a handler in the worker that would then naively throw the rejection in order to get propagation. Propagation has been desirable at least in our own internal system code support infrastructure so that tests can fail with an explicit failure instead of mysteriously timing out when some very broken thing happens inside the worker, derailing it.

asutherland avatar Feb 15 '22 17:02 asutherland

This definitely seems reasonable given the new serialization support. Thank you!

Offtopic-ish Aside: It might also be nice to consider improving the ergonomics around unhandledrejection so that they also could propagate to the Worker binding. I feel like the last time I looked at this it was necessary to add a handler in the worker that would then naively throw the rejection in order to get propagation. Propagation has been desirable at least in our own internal system code support infrastructure so that tests can fail with an explicit failure instead of mysteriously timing out when some very broken thing happens inside the worker, derailing it.

Would it be possible to take advantage of this to expose more information about the PromiseRejectionEvent event ? The same information currently exposed by ErrorEvent.

ErrorEvent.filename Read only A string containing the name of the script file in which the error occurred.

ErrorEvent.lineno Read only An integer containing the line number of the script file on which the error occurred.

ErrorEvent.colno Read only An integer containing the column number of the script file on which the error occurred.

RealAlphabet avatar May 31 '23 20:05 RealAlphabet