Skip to content

withstack: support Unwrap() []error for multi-errors - #170

Open
AdamMagued wants to merge 1 commit into
cockroachdb:masterfrom
AdamMagued:fix/multi-error-unwrap-slice-162
Open

AdamMagued wants to merge 1 commit into
cockroachdb:masterfrom
AdamMagued:fix/multi-error-unwrap-slice-162

Conversation

@AdamMagued

@AdamMagued AdamMagued commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

Fixes #162

  • withstack.WithStackDepth: Return withStackMulti when wrapped cause implements interface{ Unwrap() []error }
  • withstack.withStackMulti: Provide Unwrap() []error, Cause() error, Error() string, SafeFormatError, Format, and SafeDetails
  • withstack.GetReportableStackTrace, withstack.GetOneLineSource: Recognize ourWithStackMultiName type key
  • errbase.formatRecursive: Branch causal recursion to unwrap slice errors only when single unwrap yields nil
  • report.visitAllMulti: Branch child error recursion to prevent duplicate traversal on multi-error wrappers
  • withstack/withstack_test.go: Add tests covering withStackMulti slice unwrapping, stack capture, safe details, and single-error unwrapping
  • errutil_api_test.go: Add tests verifying errors.Join returns errors implementing interface{ Unwrap() []error }, with errors.Is and errors.As support

Test Plan

  • go test ./... in container sandbox passes cleanly
  • go mod tidy verified clean
  • errors.Join slice unwrap type assertion verified without panics

lmk if you need any adjustments


This change is Reviewable

Errors returned by errors.Join wrap the inner joined error with
withstack.WithStackDepth. Previously, withStack only implemented
Unwrap() error, causing panics when callers type asserted to
interface{ Unwrap() []error } to inspect joined errors in Go 1.20+.

Add withStackMulti which implements Unwrap() []error when the wrapped
cause provides Unwrap() []error, while preserving Cause() error,
SafeFormatError, Format, and SafeDetails. Update formatRecursive
and visitAllMulti recursion branching to avoid duplicate traversal.

Fixes cockroachdb#162

Signed-off-by: AdamMagued <adamismailmageud@gmail.com>
@cockroachlabs-cla-agent

cockroachlabs-cla-agent Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

Errors returned from Join are incompatible with errors returned the standard lib's errors.Join

1 participant