Support checking server error codes for arbitrary errors in the stable API

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Fixed
    • Priority: Unknown
    • 2.5.0
    • Affects Version/s: None
    • Component/s: Error Handling
    • None
    • 🔵 Done
    • Fully Compatible
    • Go Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      It's not possible for a user to check the error code of an error passed by event.CommandFailedEvent without relying on the experimental API:

      derr, ok := evt.Failure.(driver.Error)
      if ok {
          fmt.Println(derr.Code)
      }
      

      An example use case are the metrics implementation for otelmongo which requires providing a database status code, particularly for failures.

      Definition of done

      The team has considered two solutions.

      1. Add a Codes []string field to event.CommandFailedEvent
      2. Support for this in the stable API, such as with the function mongo.ErrorCodes():

      codes := mongo.ErrorCodes(err)
      _ = codes
      

      We should start with (1) and if that presents difficulties, attempt (2).

      Pitfalls

      We probably don't want to support a huge set of functions to parse information off arbitrary errors. Error codes feel unique, however, in that they can be acted upon.

            Assignee:
            Preston Vasquez
            Reporter:
            Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: