Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

[feature] errors.Unwrap #21

Closed
2 tasks
davecheney opened this issue May 7, 2016 · 3 comments
Closed
2 tasks

[feature] errors.Unwrap #21

davecheney opened this issue May 7, 2016 · 3 comments

Comments

@davecheney
Copy link
Member

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.

See also #18

@davecheney
Copy link
Member Author

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.

@jaekwon
Copy link

jaekwon commented Dec 30, 2017

Related proposed solution: #144

@powerman
Copy link

powerman commented Sep 5, 2019

@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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants