Skip to content

feat: implement causes() function for cause chain traversal - #5

Merged
codewizdave merged 2 commits into
devfrom
task/06-causes-function
May 29, 2026
Merged

feat: implement causes() function for cause chain traversal#5
codewizdave merged 2 commits into
devfrom
task/06-causes-function

Conversation

@martyy-code

Copy link
Copy Markdown
Contributor

Summary

Add causes(error) function that returns the causes array from an error:

consterr=ValidationError({field: 'email'}).from(newNetworkError('Connection failed'));// causes(err) returns [NetworkError]

Features

  • Returns array from most recent to root cause
  • Returns empty array for error with no cause
  • Works through multiple chaining levels
  • Works with native errors in chain
  • err.causes property already works (from Task 05)

Implementation

The function is straightforward - it returns the causes array stored on the error instance by .from(). This avoids code duplication and maintains consistency.

Test plan

  • 78 tests passing
  • TypeScript strict mode passes
  • ESLint passes

🤖 Generated with Claude Code

martyy-codeand others added 2 commits May 29, 2026 11:11
Add causes(error) function that returns the causes array from an error:
- Returns array from most recent to root cause
- Handles errors with no cause (returns empty array)
- Works through multiple chaining levels
- Works with native errors in chain
The causes property (err.causes) already works as per Task 05.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
causes() function implemented and tested. All acceptance criteria met.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for freeto 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.

2 participants

@martyy-code@codewizdave