[GODRIVER-2975] Fully support "errors.Is" and "errors.As" in all stable BSON APIs Created: 06/Sep/23  Updated: 08/Jan/24

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

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

Issue Links:
Related
is related to GODRIVER-2721 Fully support "errors.Is" and "errors... Backlog
Epic Link: Go Driver 2.0 BSON
Quarter: FY24Q3
Backwards Compatibility: Major Change
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 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.

See related ticket GODRIVER-2721 for the support in the rest of the Go driver.


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