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

Error traces are not printed with fmt %+v when outer error is not errTrace #89

Open
prashantv opened this issue Feb 15, 2024 · 2 comments

Comments

@prashantv
Copy link
Contributor

While writing some tests with errtrace, I had a scenario where the formatted error didn't have an error trace, even though underlying errors were wrapped.

Example snippet,

err1 := errtrace.Wrap(errors.New("err1"))
err2 := errtrace.Wrap(fmt.Errorf("err2: %w", err1))
err3 := fmt.Errorf("err3: %w", err2)
fmt.Printf("using fmt format:\n%+v\n========\nFormat:\n%v", err3, errtrace.FormatString(err3))

gives:

using fmt format:
err3: err2: err1
========
Format:
err3: err2: err1

main.main
	/tmp/sandbox1006302431/prog.go:13
main.main
	/tmp/sandbox1006302431/prog.go:14

Since the last error was not wrapped with errtrace, the %+v has no impact. However, FormatString does work correctly in this case.

While we can't fix this, is this gotcha worth calling out somewhere, and should we recommend errtrace.FormatString over %+v.

@abhinav
Copy link
Contributor

abhinav commented Feb 15, 2024

Yeah, we should recommend FormatString.

Although we may want to simplify the output first too #74.
I think the tree-format is more trouble than it's worth.
I doubt anybody finds that useful over just empty-line or --- separated traces.

@cbandy
Copy link
Contributor

cbandy commented Jan 29, 2025

Sounds related to #59.

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

3 participants