Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2721

Fully support "errors.Is" and "errors.As" in all stable public APIs

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 2.1.0
    • Affects Version/s: None
    • Component/s: Error Handling
    • Major Change

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: