feat: add typed error factory - #1
Merged
Merged
Conversation
- define typed error code, message, and context - preserve error causes and creation timestamps - expose public context through JSON serialization - keep internal context excluded from JSON output
- add createError factory with defaults and fixed options - resolve error types from merged factory options - recursively merge error context - preserve factory stack traces - use `@opinionated-ts/primitives` for object merging and type utilities
- Preserve literal and nested context types with `const` generics. - Replace generic context mutation with typed recursive merges. - Build only defined error options instead of spreading all sources. - Reuse the merge type to expose the exact resolved option shape.
- Avoid separate merges for public and internal context. - Skip context merging when no context is provided. - Reduce intermediate object allocations during option resolution.
|
🎉 This PR is included in version 0.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.
Why
Errorbehavior while supporting domain-specific metadata and stable codes.What
BaseErrorwithcode,message,context,cause, andcreatedAt.createErrorto generate typed factories with default and fixed configuration precedence.contextvalues recursively so public and internal data can be layered without losing sibling fields.Requirements
BaseErrorpreserves standardErrorsemantics and exposes typedcode,message,context,cause, andcreatedAt.createErrorresolves values in the orderdefaults→ per-error options →fixed.contextentries merge recursively while preserving the exact inferred types.defaultsorfixedvalues.Constraints
Related
N/A
Additional Notes
This is the first draft of the error system and is intentionally scoped to the shared typing and factory behavior needed by the rest of the ecosystem.
A runtime dependency on
@opinionated-ts/primitiveswas introduced to reuse the shared merge implementation. This keeps the implementation reusable across packages and avoids bundling duplicate merge logic, while allowing the same primitive to be reused elsewhere in the ecosystem.