How often do you wrap your errors?

When does it make snese to wrap an error with additional info ?

For example, GetObjectX() makes a REST call or a DB call, and that call returns and object and error. If that error is not nil, do oyu return it as is or wrap it with:

errors.Wrap(err, "Could not get an answer from API")

Please advice.

1 Like


Where I work we pretty much wrap all of our errors with extra information. This makes it really nice when looking at errors and you can see the entire path to where the error originated from. That being said sometimes wrapping the very “bottom” error seems pointless if your function only has one place that returns an error.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.