Skip to content

feat(error): add namespaced, serializable error domains - #7

Merged
jhnns merged 1 commit into
mainfrom
define-error-classes-subexport
Aug 5, 2026
Merged

feat(error): add namespaced, serializable error domains#7
jhnns merged 1 commit into
mainfrom
define-error-classes-subexport

Conversation

@jhnns

@jhnns jhnns commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a new error sub-export for defining namespaced, serializable error classes grouped into domains (namespacing via the existing namespace module).
  • Domains are themselves classes, so instanceof works against a whole domain (or sub-domain), not just a single error; domains are abstract and throw if instantiated directly.
  • ErrorDomain.define() batch-defines one or more error classes at once, merging context in the order domain defaults β†’ per-error defaults β†’ runtime context.
  • Errors round-trip through JSON.stringify()/errors.parse() (accepting a JSON string or an already-parsed object) via an exact-snapshot reconstruction, falling back to UnknownError for unregistered codes; stack serialization defaults to a new isDev helper (src/lib/is-dev.ts) and is configurable globally (errors.serialize.includeStack) or per call.
  • Adds the module's README, and registers it in package.json, jsr.json, .size-limit.json, and the root README's utilities table.

Test plan

  • npm run test:unit β€” 420 tests pass across the project, including 26 for the new error module
  • npm run test:types / npm run test:lint / npm run test:format
  • npm run test:build:size β€” new module measures 868 B brotli, under its 875 B limit

Adds a new `error` sub-export for defining error classes: domains are
classes (so `instanceof` works against a whole domain, not just one
error), error codes are namespaced via the existing `namespace` module,
context merges domain defaults -> per-error defaults -> runtime context,
and errors round-trip through JSON via `toJSON()`/`errors.parse()` with
an `UnknownError` fallback for unregistered codes. Stack serialization
defaults to `isDev` (new `src/lib/is-dev.ts` helper) and is configurable
globally or per call.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jhnns
jhnns merged commit b9e7b41 into main Aug 5, 2026
2 checks passed
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 30963464752

Coverage increased (+0.05%) to 95.68%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 57 of 57 lines across 3 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 632
Covered Lines: 619
Line Coverage: 97.94%
Relevant Branches: 317
Covered Branches: 289
Branch Coverage: 91.17%
Branches in Coverage %: Yes
Coverage Strength: 15.25 hits per line

πŸ’› - Coveralls

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant