some-grass-63999
01/25/2023, 6:28 PMreturn
, as is pretty common in Go. When the resource fail for whatever reason, it's hard to track down in the codebase where athey are happening. Are there are tricks to doing this? I've tried using something like https://github.com/pkg/errors, or even hand-rolling our own error with a callstack, but that hasn't deemed super successful. I'm hesitant to use panic
everywhere, though that may be more helpful as I will know where the errors are occurring.
Any advice on error handling in go to make it easier to track down where issues are happening? Thanks!purple-coat-73595
01/25/2023, 8:50 PMif err != nil {
return errors.Wrapf(err, "message with error context goes here")
}
It is not bad and I usually can track down any error. But I must say I don't like it.some-grass-63999
01/26/2023, 12:04 AMgifted-fall-44000
01/26/2023, 1:21 AMpurple-coat-73595
01/26/2023, 5:17 PMfunc main() {
err := errors.New("something very bad happened")
err = errors.Wrap(err, "even worse")
err = errors.Wrap(err, "bad bad")
fmt.Printf("%+v", err)
}
(note "%+v"
)func main() {
err := func1()
fmt.Printf("%+v", err)
}
func func1() error {
return func2()
}
func func2() error {
return errors.New("something very bad happened")
}
this one also prints the call stack