3 ms·
I would love a syntactic sugar for 'if err == nil {Errors.Wrap(err, *What I was trying to do")}'. As a SRE, making each part of the stack explicit (or explicitl
by GauntletWizard 5y ago
I would love a syntactic sugar for 'if err == nil {Errors.Wrap(err, *What I was trying to do")}'. As a SRE, making each part of the stack explicit (or explicitly non-explicit) is invaluable for understanding debugging. I'm A-ok with some forms of error throwing, but they need to be clear and understood.
- unscaled 5y agoI think you meant the code: if err != nil { return fmt.Errorf("What I was trying to do: %w") } That's the correct and standard way to do error wrapping in Go since Go 1.13[1]. There is also Dave Cheney's pkg/errors[2] which does define "errors.Wrap()", but that has been superseded by the native functionality in Go. [1]: https://go.dev/blog/go1.13-errors https://go.dev/blog/go1.13-errors [2]: https://github.com/pkg/errors https://github.com/pkg/errors
- GauntletWizard 5y agoThe code I'm primarily working on is old enough that Errors.Wrap is the standard - Though refactoring that is definitely on the radar :)