Wrapping Go errors with caller info
I find Go’s error handling refreshingly simple & clear. Nowadays, all I do is wrap my errors using fmt.Errorf with some additional context. The pattern I tend to use most of the time just includes a function/method name, like so: func someFunction() error { err := someStruct{}.someMethod() return fmt.Errorf("someFunction: %w", err) } type someStruct struct { } func (ss someStruct) someMethod() error { return fmt.Errorf("someMethod: %w", errors.New("boom")) } If I now call someFunction, the error - when logged or printed - will look like this: someFunction: someMethod: boom. This gives just enough context to figure out what happened, and where. ...