rollrus
rollrus copied to clipboard
extractError() will discard stack if root cause doesn't have a stack trace attached
Since extractError()
only looks at the root cause and discards other errors in the error stack (https://github.com/heroku/rollrus/blob/master/rollrus.go#L270-L275), if there are multiple wrapped errors and the root cause does not have a stacktrace, it will discard the stacktraces from the other errors. I propose that it uses the deepest stack it can find:
func getDeepestStackTrace(err error) errors.StackTrace {
type errorCauser interface {
Cause() error
}
type stackTracer interface {
StackTrace() errors.StackTrace
}
var deepestStackTrace errors.StackTrace
for {
if tracer, ok := err.(stackTracer); ok {
deepestStackTrace = tracer.StackTrace()
}
if causer, ok := err.(errorCauser); ok {
err = causer.Cause()
} else {
break
}
}
return deepestStackTrace
}
Care to PR a failing test that shows how you would like it to work?