Uh oh!
There was an error while loading. Please reload this page.
feat: implement .from() method for exception chaining - #4
Merged
Conversation
Add .from(cause) method to ErrorInstance: - Sets the cause property on the error - Maintains full cause chain in causes array - Supports method chaining (err.from(a).from(b)) - Works with native errors and custom error factories - Preserves nested cause chains Implementation: - Added .from() method to ErrorInstance type - Method returns instance for chaining - Causes array maintains chronological order: newest first Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
martyy-code
commented
May 29, 2026
martyy-code
left a comment
ContributorAuthor
There was a problem hiding this comment.
PR Review: feat: implement .from() method for exception chaining
Summary
The .from() implementation for exception chaining is well-designed and correctly handles the core requirements. The cause chain building logic properly preserves nested cause arrays and maintains chronological order.
What Works Well
- Correct cause chain building: The spread order
[cause, ...cause.causes, ...instance.causes]correctly maintains newest-first ordering - Handles native errors: Properly defaults to
[]when cause has nocausesproperty (native Error objects) - Type signature is correct:
from(cause: Error | ErrorInstance): ErrorInstance<TFields>matches the implementation that checks forcausesproperty - Method chaining: Returns
instanceallowing.from(a).from(b)pattern - Test coverage: Comprehensive tests covering basic usage, nested chains, chaining, type safety, and edge cases
Suggestion (Non-blocking)
The type guard 'causes' in cause && Array.isArray(cause.causes) could theoretically fail if someone attached a non-array causes property to an error. However, this is an extremely unlikely scenario that does not warrant a blocking issue.
Recommendation
Approve - The implementation is clean, well-tested, and follows the design correctly.
15 tasks
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 freeto 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.
Summary
Add
.from(cause)method to ErrorInstance for exception chaining:Features
err.causepropertyerr.causesarray with complete historyerr.from(a).from(b)worksImplementation
.from()method to ErrorInstance typeTest plan
🤖 Generated with Claude Code