Introduce new `structerr` package
Most of our codebase is nowadays using the helper.Err
functions to
format errors. While those are nice to propagate error codes across the
codebase, they fall short to provide a more structured way of handling
errors.
Right now we're between a rock and a hard place when it comes to providing context when an error happens:
- We can return a static error message. This has the benefit that
the generated errors are brief and easily greppable, and because
they are static it allows Sentry to properly deduplicate them. But
the big downside is that you can now only log additional context
via a separate log entry, and this makes it hard to correlate the
errors with that additional log.
- On the other hand, we can try to add all information to the error
message. While this now provides all the necessary context, it
causes the error message to balloon in size. This both makes them
hard to digest and trips Sentry.
Introduce a new structerr
package to help solve this problem. Right
now it really only does the same as the helper functions. But by using a
new dedicated structerr.Error
, we can iterate on its functionality and
add additional information to this error. Eventually, this package will
replace our helper.Err
functions completely.