3 ms·
I 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 wrapp
by unscaled 5y ago
I 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 :)