Skip to content

feat(error): expose causes to errors.Is and errors.As - #31

Merged
yordis merged 3 commits into
mainfrom
yordis/feat-cause-traversal
Oct 7, 2026
Merged

yordis merged 3 commits into
mainfrom
yordis/feat-cause-traversal

Conversation

@yordis

@yordis yordis commented Oct 7, 2026 •

Copy link
Copy Markdown
Member
  • Causes added through WithCause were invisible to errors.Is and errors.As, since only the error from WithWrap was reachable through Unwrap. Callers had to walk Causes() by hand to detect a nested failure, which defeats the purpose of recording causes in the first place.
  • The Unwrap() error signature is kept so existing callers and errors.Unwrap consumers keep working. The multi-child traversal lives on the private causes type instead, which lets the standard library do the walking rather than hand-rolling Is and As.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core Unwrap/Is behavior for errors that use WithCause, which can alter how callers match errors at runtime; behavior is well-tested but is a semantic change in a foundational error type.

Overview
TrogonError now participates fully in Go’s error chain so errors.Is and errors.As can see failures attached with WithCause, not only the value from WithWrap.

Unwrap() still returns a single error, but when causes exist it returns a private causes slice (or errors.Join of the wrapped error and causes) that implements multi-child Unwrap() []error, so the standard library walks wrapped errors and every cause—including nested ones. Non-TrogonError targets in Is() are resolved via errors.Is(e.Unwrap(), target) instead of checking wrappedErr alone. WithCause skips nil entries so mixed nil/real causes do not break unwrapping.

Package docs describe the new behavior, and tests cover nested causes, sentinels inside causes, errors.As, and nil-cause edge cases.

Reviewed by Cursor Bugbot for commit df1a3fd. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8bbd588f-e836-40b2-9233-1dc6b71e335b
📥 Commits

Reviewing files that changed from the base of the PR and between 35182a3 and df1a3fd.

📒 Files selected for processing (3)
  • doc.go
  • error.go
  • error_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

TrogonError exposes wrapped errors and causes through Go’s standard error traversal. WithCause ignores nil causes. Tests and documentation cover errors.Is and errors.As matching errors in the cause chain.

Changes

Error cause traversal

Layer / File(s) Summary
Cause representation and traversal
error.go, error_test.go, doc.go
TrogonError now exposes wrapped errors and causes through Unwrap, combining both when present. Is checks the unwrapped error. WithCause omits nil causes. Tests cover errors.Is, errors.As, and Unwrap; the documentation describes cause-chain matching.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to df1a3

The cause-traversal change is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: making causes reachable by errors.Is and errors.As.
Description check ✅ Passed The description directly explains the previous limitation, the intended behavior, and the compatibility approach for Unwrap.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit follows errors down the chain
Past wrapped clues and causes in the rain
Is finds the sentinel tucked away
As brings a custom type to play
Nil causes hop off without a trace
And every error finds its place

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e13188c. Configure here.

Comment thread error.go
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis merged commit a3b0bf6 into main Oct 7, 2026
4 checks passed
@yordis
yordis deleted the yordis/feat-cause-traversal branch October 7, 2026 18:24
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