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

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Go Drivers
    • 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?
    • 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: