Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cyrusaf opened this issue Nov 27, 2018 · 1 comment

Comments

@cyrusaf
Copy link

cyrusaf commented Nov 27, 2018

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 cyrusaf changed the title extractError will discard stack if root cause doesn't have a stack trace attached extractError() will discard stack if root cause doesn't have a stack trace attached Nov 27, 2018
@freeformz freeformz self-assigned this Aug 8, 2019
@freeformz
Copy link
Contributor

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

@freeformz freeformz removed their assignment Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants