bugsnag-js icon indicating copy to clipboard operation
bugsnag-js copied to clipboard

Web Worker error notifying

Open jmshal opened this issue 8 years ago • 7 comments

Right now you can technically catch errors from Workers by listening to it's onerror event. However it seems (at a first glance) that the stacktrace is lost. It might be worth having an additional (tiny) script to import within a worker which basically proxies the error & stacktrace back to the main thread for it to notify (making the worker completely config-less).

I still have to see what's technically possible, but I'm pretty confident it can be done.

Thoughts?

jmshal avatar Aug 08 '16 09:08 jmshal

Thanks for the report, @jacobmarshall. Seems like kinda of a hairy issue, but I'm open to ideas. 🤔 @eanakashima @wordofchristian might also have some thoughts.

kattrali avatar Aug 13 '16 01:08 kattrali

I think it would be very reliant on how #170 turns out.

jmshal avatar Aug 13 '16 05:08 jmshal

Does #170 solve the stacktrace problem, or is more required?

foxyblocks avatar Aug 15 '16 17:08 foxyblocks

More is required, as the error needs to be caught from within the worker in order to extract the stacktrace. If you'd like I can combine this into #170?

jmshal avatar Aug 15 '16 18:08 jmshal

As with #170, we are going to pick this up in the next major.

bengourley avatar Aug 30 '17 09:08 bengourley

It appears that a major release has come and gone since that last ^ comment. Is this still planned?

JacobEvelyn avatar Oct 24 '18 12:10 JacobEvelyn

For anyone here who saw @jmshal's statement

Right now you can technically catch errors from Workers by listening to its onerror event.

and is wondering how to actually do that, I dug through the code for a while and eventually came up with this:

worker.onerror = function(errorEvent) {
  const bugsnagReport = new bugsnagClient.BugsnagReport(
    "worker.onerror",
    errorEvent.message,
    [
      {
        fileName: errorEvent.filename,
        lineNumber: errorEvent.lineno,
        columnNumber: errorEvent.colno
      }
    ],
    {
      severity: "error",
      unhandled: true,
      severityReason: { type: "unhandledException" }
    }
  );

  bugsnagClient.notify(bugsnagReport);
};

Since the ErrorEvent interface is used for every error event except for window.onerror, I wonder if it makes sense to allow Bugsnag.notify to take an ErrorEvent and just change Bugsnag's window.onerror (which does not pass an ErrorEvent—see MDN doc) to window.addEventListener("error", ...) (which does). Thoughts?

JacobEvelyn avatar Oct 26 '18 12:10 JacobEvelyn

Hi all, just writing to let you know that we recently released support for Web Workers in bugsnag-js: https://github.com/bugsnag/bugsnag-js/releases/tag/v7.20.0

You can read more about this in our docs: https://docs.bugsnag.com/platforms/javascript/web-workers/

johnkiely1 avatar Feb 17 '23 10:02 johnkiely1