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

Preserve error stack traces across contexts #34

Open
fregante opened this issue Oct 1, 2021 · 1 comment
Open

Preserve error stack traces across contexts #34

fregante opened this issue Oct 1, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@fregante
Copy link
Collaborator

fregante commented Oct 1, 2021

  1. content.js calls myGet()
  2. myGet’s handler returns an error in the background page
  3. content.js throws the error

Since the error was generated in the background page, its stack trace won't have any reference to myGet() nor its origin. Only the console will point to the throw Error inside the response handler, but nothing before that.

Maybe something like this will append the current stack trace to the error that was received:

  const error = deserializeError(response.error);
+ error.stack += Error.captureStackTrace();
  throw error;

or

@fregante fregante added the enhancement New feature or request label Oct 1, 2021
@fregante
Copy link
Collaborator Author

fregante commented Nov 9, 2024

I implemented this in my mini-library via Error#cause. In short, instead of deserializing the error and throwing it, I throw a new error and deserialize the other one into cause

https://github.com/fregante/webext-msg/blob/e8796cb1ecf5c81c3e07b9263a8223487df86760/index.ts#L30-L34

I think that in order to do the same here you'd have to drop the polyfill: Actually, not necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant