-
Notifications
You must be signed in to change notification settings - Fork 698
Wrap() duplicates call stack #242
Comments
Yes, this is how it works. I couldn’t think of an algorithm to collapse related stack frames. I recommend not using WithStack at intermediary levels as it adds little value. WithStack was added because sometimes errors cross stack boudnaires, ie being lsssd through a channel to another goroutine. |
This is a well known caveat with As davecheney points out, it’s really hard to algorithmically figure out when and where a stack trace should be attached, while for humans it’s a comparatively simple matter of policy enforcement. |
@davecheney @puellanivis Thank you so much for your reply. |
@davecheney @puellanivis , I understood
Ps: I am very new to Golang, so please point out If I am missing out on something very obvious. |
We already have as rich of an error type as is feasible to represent an error with a stack. It is not really feasible that functions should return any error type other than It is not always the right thing to do to never allow adding a secondary stacktrace. In 99% of cases, it never makes sense, but especially if a piece of code has a significant amount of error handling, a second stacktrace might actually make sense. |
Got it. Thank you @puellanivis. |
I am currently considering using pkg/errors.
However, I have a question, so I'm leaving a question.
I ran the example code and expected the output shown in the code comments.
However, if you look at the output attached below, you can see that the output is completely different. The problem is that duplicate stacks are displayed.
And this also happens when I wrap the error passed to New() and WithStack(). Is this the intended behavior?
Environment:
pkg/errors version: 0.9.1
Go version: 1.16
OS version: macOS Big Sur 11.0.1
My output:
The text was updated successfully, but these errors were encountered: