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

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

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

      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?

      Show
      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?

      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.

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

              Created:
              Updated: