[GODRIVER-2721] Fully support "errors.Is" and "errors.As" in all stable public APIs Created: 23/Dec/22  Updated: 08/Jan/24

Status: Backlog
Project: Go Driver
Component/s: Error Handling
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: rp-track
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2929 Improve error messaging by wrapping e... Backlog
related to GODRIVER-2975 Fully support "errors.Is" and "errors... Backlog
is related to GODRIVER-2603 Use errors API from Go 1.13 Closed
Epic Link: Go Driver 2.0: Driver
Backwards Compatibility: Major Change

 Description   

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.

Note: The scope of this ticket is limited to all Go driver code except the BSON library. See related ticket GODRIVER-2721 for the support in the Go driver BSON library.


Generated at Thu Feb 08 08:39:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.