IsDuplicateKeyError doesn’t work with ClientBulkWriteException

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • 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

      Detailed steps to reproduce the problem?

      ```
      func IsDuplicateKeyError(err error) bool {
      if se := ServerError(nil); errors.As(err, &se)

      { return se.HasErrorCode(11000) || // Duplicate key error. se.HasErrorCode(11001) || // Duplicate key error on update. // Duplicate key error in a capped collection. See SERVER-7164. se.HasErrorCode(12582) || // Mongos insert error caused by a duplicate key error. See // SERVER-11493. se.HasErrorCodeWithMessage(16460, " E11000 ") }

      return false
      }
      ```
      Client.BulkWriteException doesn’t implement ServerError, so it can never return true here.

      This is a sharp edge: a user would expect a driver-sourced error to work with this interface.

      Definition of done: what must be done to consider the task complete?

      One of:

      1. Make ClientBulkWriteException implement ServerError
      2. Rewrite this function so it works as would be expected.

      The exact Go version used, with patch level:

      1.26.4

      The exact version of the Go driver used:

      2.7.0

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      Security Vulnerabilities

      If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here

            Assignee:
            Unassigned
            Reporter:
            Felipe Gasper
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: