Hacker News new | ask | show | jobs
by unscaled 1714 days 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 [2]: https://github.com/pkg/errors

1 comments

The code I'm primarily working on is old enough that Errors.Wrap is the standard - Though refactoring that is definitely on the radar :)