rollrus icon indicating copy to clipboard operation
rollrus copied to clipboard

extractError() will discard stack if root cause doesn't have a stack trace attached

Open cyrusaf opened this issue 6 years ago • 1 comments

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
}

cyrusaf avatar Nov 27 '18 20:11 cyrusaf

Care to PR a failing test that shows how you would like it to work?

freeformz avatar Aug 08 '19 22:08 freeformz