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.