OperationError#code not set on duplicate key error

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 2.7.0.rc0, 2.6.4
    • Affects Version/s: 2.6.0
    • Component/s: None
    • None
    • Environment:
      Tested on MongoDB 3.4 and 3.6 with Ruby 2.5 and JRuby 9.2.0.0
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      On certain kinds of errors like duplicate key errors, no code is set on the OperationError exception. 

      Steps to reproduce:

      require 'mongo'
      client = Mongo::Client.new("mongodb://localhost/test")
      
      begin
        client['test'].insert_one(_id: '1')
        client['test'].insert_one(_id: '1')
      rescue => e
        puts "Code: #{e.code.inspect}"
      end
      

      Expected Result:

      Prints "Code 11000"

      Actual Result:

      Prints "Code nil"

              Assignee:
              Oleg Pudeyev (Inactive)
              Reporter:
              Andreas Gerauer
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: