Skip to content

fix: set the name of the error classes - #13

Merged
milamer merged 1 commit into
mainfrom
fix/error-class-names
Nov 9, 2026
Merged

milamer merged 1 commit into
mainfrom
fix/error-class-names

Conversation

@milamer

@milamer milamer commented Nov 9, 2026

Copy link
Copy Markdown
Owner

DuplicateKeyError, MixedArrayError, ForbiddenKeyError and DepthLimitError reported name === 'Error', so String(error), logs and stack traces started with Error:. In the minified UMD build the constructor names are mangled too (e/t), so error.constructor.name didn't help either.

Change

  • Each class sets this.name to its class name as a string literal (new.target.name/this.constructor.name would be renamed by the minifier).
  • V8 formats the stack header lazily, so error.stack starts with the class name as well.

Tests

  • src/__tests__/index.ts: for each class, an error thrown by parseFormData is an instance of its class and of Error, has the right name, String(error) is <Name>: <message>, and stack starts with <Name>: . These fail on main.
  • scripts/smoke-dist.mjs: checks name and String(error) for every error export in all builds (cjs, esm, umd, umd.min, and both UMD files loaded as a <script>).

Compatibility

Only name changes (from 'Error' to the class name). Messages, key, instanceof and exports are unchanged. Code that checked error.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.

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-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d549dd3) to head (61cc5eb).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@milamer
milamer merged commit 37580df into main Nov 9, 2026
7 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants