-
The func (f *fundamental) Format(s fmt.State, verb rune) {
io.WriteString(s, f.msg)
f.stack.Format(s, verb)
} https://github.com/kohofinancial/errors/blob/master/errors.go#L147 And func (f *fundamental) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
if s.Flag('+') {
io.WriteString(s, f.msg)
f.stack.Format(s, verb)
return
}
fallthrough
case 's':
io.WriteString(s, f.msg)
case 'q':
fmt.Fprintf(s, "%q", f.msg)
}
} https://github.com/pkg/errors/blob/master/errors.go#L127 The result of our version is that it is not possible to print the error message without the stack trace. I want to improve our DataDog error integration by providing error metadata but this requires being able to read the message separate from the stack trace. The commit creating this difference is here indicating that this is intentional: https://github.com/kohofinancial/errors/commit/e2946ae3a7736210a5fea4f873cdba6be7d5ed46 What are @kohofinancial/nomads current thoughts on undoing our diversion? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I am in favour of this, and to go further, I think the stack trace is noise 95% of the time and I wish I had a carefully wrapped error instead. I'm really not interested in half a dozen middleware stack frames. Since Go 1.13, the stdlib error package provides the If we switch to stlib errors, the migration is also quite easy: we can just start using it, and migrate existing services over slowly, as it's a different import path. The Go blog article about error handling for Go 1.13+ is my go-to reference about when to wrap, and errors in general. |
Beta Was this translation helpful? Give feedback.
I am in favour of this, and to go further, I think the stack trace is noise 95% of the time and I wish I had a carefully wrapped error instead. I'm really not interested in half a dozen middleware stack frames.
Since Go 1.13, the stdlib error package provides the
%w
formatting directive, and withIs
,As
, andUnwrap
, we have all we need. This would require re-thinking (or starting to think) about things like when to wrap, be more careful about logging only after bubbling up etc., but I think it would potentially make errors much more useful.If we switch to stlib errors, the migration is also quite easy: we can just start using it, and migrate existing services over slowly, as it's a diffe…