Fix error stack traces by using error classes #92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Breaking Changes
Replace pre-instantiated singleton errors with error classes to enable stack traces.
You can already provide your own errors which also gets around this, but that would require remembering doing that at all call sites. And then telling every other consumer of this library to also do that. So, not working well in practice.
Before:
After:
Motivation
Singleton errors captured stack traces at module load time, making them not-great for debugging. Error classes provide stack traces for each error occurrence.
Changes
E_TIMEOUT,E_ALREADY_LOCKED,E_CANCELEDexports withTimeoutError,AlreadyLockedError,CanceledErrorclassesObject.setPrototypeOf()to fixinstanceofbehavior in ES5 targets~50 bytes bundle size increase, because of ES5 support. Could probably remove or write it in ES5-style directly.
Migration
TypeScript users: Compile errors will guide migration.
JavaScript users (ESM): Import errors will make any upgrade fail when loading.
The non-ESM-story I guess will get a runtime error, if they upgrade to a 1.0 version (which this should be if taken in) without checking for breaking changes.