The Go driver was built before the "modern" Go error handling paradigm using errors.Is and errors.As were added. As a result, handling errors when using the Go driver frequently requires checking for individual errors, writing error switch statements, and using error helper functions. Additionally, errors returned from the Go driver sometimes lack sufficient information to determine the root cause of an error.
We should try to reduce the amount of individual error value comparison required and instead aim to support the errors.Is and errors.As for all stable (i.e. not in x/ public Go driver APIs.
Definition of done:
- Audit all exported error values and remove those that can be replaced by a class of errors (e.g. InvalidArgumentError, see GODRIVER-1854).
- Wrap all errors returned by stable public APIs using fmt.Errorf("...: %w", err) or a similar pattern.
- Replace all uses of the internal errutil.WrapErrorf (if it's still used) with fmt.Errorf using the "%w" verb.
- Update tests to use errors.Is and errors.As instead of direct error comparison.
- Enable the errorlint linter in golangci-lint to check for error use patterns that cause problems using errors.Is and errors.As.
- Enable the wrapcheck linter.
- Consider copying the Go stdlib errors.Join code into the errutil package to support multi-errors.
See related ticket GODRIVER-2721 for the support in the rest of the Go driver.
- is related to
-
GODRIVER-2721 Fully support "errors.Is" and "errors.As" in all stable public APIs
- Backlog
- related to
-
GODRIVER-2775 Remove the "replaceErrors" function
- Backlog