kubeadmiral icon indicating copy to clipboard operation
kubeadmiral copied to clipboard

Replace `github.com/pkg/errors` with `fmt`?

Open gary-lgy opened this issue 1 year ago • 2 comments

The former has not been maintained since 2021. The latter is not a complete replacement of the former, because the former adds stack traces to errors. However, we are not making use of stack traces in errors.

Should we replace the former with the latter?

gary-lgy avatar Jun 09 '23 05:06 gary-lgy

There are several things we can improve about errors altogether:

  • Interaction with tracing
  • Structural errors
  • Exposing errors to metrics
  • Unify error format

We can improve all of these together with comparable time investment.

SOF3 avatar Jun 09 '23 07:06 SOF3

Shameless plug: you can also switch it to drop-in replacement gitlab.com/tozd/go/errors. It fixes many issues, is maintained, and supports modern Go's error patterns (sentinel errors, %w formatting, joined errors, etc.). It also provides some nice utility functions and structured details so that it is easy to extract dynamic data out of errors (instead of trying to get them out of formatted strings). Has improved error formatting and JSON marshaling of errors. It is interoperable with other errors packages and does not require a dependency on it to extract data (e.g., stack trace) from errors.

From the list above, it provides structural errors and unified error formatting (even for errors which come from other errors packages/approaches so it works well in large codebases with mixed errors dependencies). Because it supports structural errors (called details) it is also easy to add metrics to errors. And JSON support helps with logging storage.

mitar avatar Oct 09 '23 06:10 mitar