go-errors / errors

errors with stacktraces for go
https://godoc.org/github.com/go-errors/errors
MIT License
921 stars 93 forks source link

Incomplete Stacktrace #46

Closed ghostsquad closed 11 months ago

ghostsquad commented 11 months ago

https://go.dev/play/p/ThypuXRoewr

*fmt.wrapError FATAL: failed to do stuff: failed to do conditional1 stuff: file not found
/tmp/sandbox1705693913/prog.go:15 (0x48331d)
/usr/local/go-faketime/src/runtime/internal/atomic/types.go:194 (0x4338b2)
/usr/local/go-faketime/src/runtime/asm_amd64.s:1650 (0x45d141)

This only seems to print the last part of the stack trace. Am I doing something wrong? If so, maybe someone can show me what I'm doing wrong, and I can submit a PR to update the documentation. Thanks for your time!

ConradIrwin commented 11 months ago

Yes! This is confusing. We added errors.Errorf so that you didn't have to import the standard library "errors" and get a name conflict – that was probably a mistake; because this library does not handle %w specially.

The original motivation for me was to have errors with stacks. I am not a fan of the "keep adding context to the error message", because it's a lot more work, and less effective than just seeing the stack trace. If you want this library to get good results you need to use errors.Wrap() and not errors.Errorf; but that does mean that there is no way to add more words to the error message.

ghostsquad commented 11 months ago

Oh. Ya, definitely want to add more context and get the stack trace.