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

refactor: avoid early initialisation of common errors #163

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

owenpearson
Copy link
Member

@owenpearson owenpearson commented Sep 5, 2023

JavaScript stack straces are created upon initialisation of the Error object, so when errors are initialised ahead of the time they are thrown, the stack trace will not show the context of where/why the error was thrown, only the context of how the Errors.ts module was first loaded.

We used to do the same thing in ably-js until someone pointed out that they were getting misleading stack traces, see:

JavaScript stack straces are created upon initialisation of the
`Error` object, so when errors are initialised ahead of the time they
are thrown, the stack trace will not show the context of where/why the
error was thrown.
Copy link
Contributor

@dpiatek dpiatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff, thanks Owen

@dpiatek dpiatek merged commit 6513cd0 into main Sep 5, 2023
5 checks passed
@dpiatek dpiatek deleted the avoid-early-error-init branch September 5, 2023 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants