Repository navigation
fix: set the name of the error classes - #13
Merged
Merged
Conversation
DuplicateKeyError, MixedArrayError, ForbiddenKeyError and DepthLimitError reported `name === 'Error'`, so `String(error)` and stack traces started with `Error:`. Each class now sets `this.name` as a string literal, which survives minification (the minified UMD build renames the classes).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 121 125 +4
Branches 44 44
=========================================
+ Hits 121 125 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
🎉 This PR is included in version 1.1.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
DuplicateKeyError,MixedArrayError,ForbiddenKeyErrorandDepthLimitErrorreportedname === 'Error', soString(error), logs and stack traces started withError:. In the minified UMD build the constructor names are mangled too (e/t), soerror.constructor.namedidn't help either.Change
this.nameto its class name as a string literal (new.target.name/this.constructor.namewould be renamed by the minifier).error.stackstarts with the class name as well.Tests
src/__tests__/index.ts: for each class, an error thrown byparseFormDatais an instance of its class and ofError, has the rightname,String(error)is<Name>: <message>, andstackstarts with<Name>:. These fail onmain.scripts/smoke-dist.mjs: checksnameandString(error)for every error export in all builds (cjs, esm, umd, umd.min, and both UMD files loaded as a<script>).Compatibility
Only
namechanges (from'Error'to the class name). Messages,key,instanceofand exports are unchanged. Code that checkederror.name === 'Error'would see a different value. Mention this in the release notes.Size
ESM 1322 B → 1335 B, umd.min 1472 B → 1497 B. Both are under the 1.5 kB limit, but umd.min now has only 3 B left.