Preserve construction error causes without extra branches
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user