This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 698
Cause - Last error with stack #173
Comments
It isn't possible today. I just needed func Stack(err error) errors.StackTrace {
type causer interface {
Cause() error
}
type stackTracer interface {
StackTrace() errors.StackTrace
}
switch err := err.(type) {
case stackTracer:
return err.StackTrace()
case causer:
return Stack(err.Cause())
}
return nil
} If it returns |
This code example would return the first StackTrace. (It tests for The original post wants to find the last StackTrace in the chain, rather than the first. |
Yup. I wrote it to do what I needed. But it wouldn't take much to change it to return the stack from the last error that had one. |
works to me. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
Let's assume we have some nested errors:
I would like to have the "last" error which has a stack. In this case it would be the one that is returned by customFunctionWhichWrapsErrors. But when I call errors.Cause I get the someBuiltErrorWithoutStack since this is the last one in the nesting.
Is this somehow possible without writing custom code?
The text was updated successfully, but these errors were encountered: