Preserve construction error causes without extra branches

This commit is contained in:
2026-11-16 19:44:09 +00:00
parent fcbff80ab2
commit 4939fdb283
4 changed files with 75 additions and 9 deletions

View File

@@ -21,6 +21,10 @@ type publicOperationError struct {
message string
}
func newPublicOperationError(owner, cause error) *publicOperationError {
return &publicOperationError{owner: owner, cause: cause, message: fmt.Sprintf("%v: %v", owner, cause)}
}
func (e *publicOperationError) Error() string { return e.message }
func (e *publicOperationError) Unwrap() error { return e.cause }
func (e *publicOperationError) Is(target error) bool { return errors.Is(e.owner, target) }
@@ -44,7 +48,7 @@ func mapPublicError(err error) error {
}
// The projection already retains ordinary causes; adding the original
// again would duplicate its entire subtree at each enclosing operation.
return &publicOperationError{owner: owner, cause: mapped, message: fmt.Sprintf("%v: %v", owner, mapped)}
return newPublicOperationError(owner, mapped)
}
}
return mapUnownedPublicError(err)