You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
We have Wrap which takes an error and returns a new error which supports Cause and will return the original error.
This issue is to discuss adding a complement to Wrap, Unwrap is specified as follows
// Unwrap reverses the Wrap process above, returning the direct cause
// of the error. If the error does not support Cause, or the error is nil, the
// error value is returned unmodified.
func Unwrap(err error) error
For discussion
Is this useful enough to justify adding to the package, vs doing this with a switch statement ?
Is the API appropriate, specifically in the case of an error which does not have a cause.
I'm going to close this as I think it's going in the wrong direction.
The original design of this errors package mirror'd Juju's which requires callers to manually wrap each level of error return to record a stack trace. Apart from this being incomplete and verbose, on reflection I think the natural stack trace recorded at the point the error happens is probably good enough (tm) for most use cases. In the cases where they are not, errors.Wrap allows the caller to add additional context to the error path.
In either cases the printing of this stack detail, including the nested stacks now possible since #27 makes this method less useful.
@davecheney Maybe it's worth to reconsider this now? It may be very useful to provide Unwrap() compatible with stdlib's errors, to make it easier to migrate existing codebase from pkg/errors to stdlib's errors or use both in parallel.
I mean, I'd like to replace errors.Cause() with errors.Is() in existing code, but this require pkg/errors to support Unwrap().
YuJuncen
added a commit
to YuJuncen/errors
that referenced
this issue
Apr 15, 2021
We have
Wrap
which takes anerror
and returns a newerror
which supportsCause
and will return the original error.This issue is to discuss adding a complement to
Wrap
,Unwrap
is specified as followsFor discussion
See also #18
The text was updated successfully, but these errors were encountered: