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

Consider adding globalThis.reportError() #41

Open
andreubotella opened this issue May 10, 2023 · 3 comments
Open

Consider adding globalThis.reportError() #41

andreubotella opened this issue May 10, 2023 · 3 comments

Comments

@andreubotella
Copy link
Member

andreubotella commented May 10, 2023

The HTML spec defines a reportError function which takes a JS value (usually an exception object) and acts as if that value had been thrown, without actually stopping the execution of the current function and its callstack. This seems fairly useful in server-side environments.

Acting "as if the value had been thrown" in browsers includes firing an error event at the global, propagating up the chain of workers if called inside a dedicated worker, and eventually, if the error is not handled at any step along the way, logging the corresponding error message on the console.

However, specifying this for server-side runtimes would involve having to deal with the runtime's existing error handling mechanisms, which might be quite different to those in browsers. (See also #29)

@ljharb
Copy link
Member

ljharb commented May 10, 2023

See nodejs/node#38947 / nodejs/node#41912

@andreubotella
Copy link
Member Author

Also denoland/deno#13484 (comment) for the discussion about adding it to Deno, which did end up happening.

Note that patterns such as setTimeout(() => {throw err;}, 1) are used on Node.js code, so it's not like this API wouldn't find any use.

On that note, the "report an error" spec algorithm is used by a number of the APIs in the list, and we should probably mention that runtimes which claim to be WinterCG-compatible can override the behavior of this algorithm to exit instead.

@jasnell
Copy link
Contributor

jasnell commented Apr 10, 2024

PR to add reportError(...) to workers cloudflare/workerd#1979

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

No branches or pull requests

3 participants