Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-907

Error message parser throws TypeError

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.4
    • Component/s: Public API
    • Labels:
      None
    • Environment:
      ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
      mongo (2.0.3)

      Description

      Inserting a document with a write concern larger than the available nodes returns an error message which fails to be parsed.

      require 'mongo'
      Mongo::Logger.logger.level = Logger::DEBUG
      client = Mongo::Client.new([ 'localhost:27017' ], :write => { :w => 50 }, :database => 'test', :replica_set => 'tank')
      collection = client['items']
      collection.insert_one({ foo: 'bar' })
      D, [2015-05-01T00:28:25.844398 #8441] DEBUG -- : MONGODB | COMMAND | namespace=test.$cmd selector={:insert=>"items", :documents=>[{:foo=>"bar", :_id=><BSON::ObjectId:0x70219847237060 data=5542ac894d424120f9000000>}], :writeConcern=>{:w=>50}, :ordered=>true} flags=[] limit=-1 skip=0 project=nil | runtime: 1.8213ms
      TypeError: no implicit conversion of String into Integer
      from ~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/mongo-2.0.3/lib/mongo/error/parser.rb:55:in `[]'
      

      This gets passed to parser.rb:55:parse_single before the exception:

      {"ok"=>1, "n"=>1, "lastOp"=>#<BSON::Timestamp:0x007fded5a1c848 @seconds=1430431846, @increment=1>, "electionId"=><BSON::ObjectId:0x70297521798740 data=55429352e2bc3896d7ed9c2b>, "writeConcernError"=>{"code"=>100, "errmsg"=>"Not enough data-bearing nodes"}}
      {"ok"=>1, "n"=>1, "lastOp"=>#<BSON::Timestamp:0x007fded5a1c848 @seconds=1430431846, @increment=1>, "electionId"=><BSON::ObjectId:0x70297521798740 data=55429352e2bc3896d7ed9c2b>, "writeConcernError"=>{"code"=>100, "errmsg"=>"Not enough data-bearing nodes"}}
      {"ok"=>1, "n"=>1, "lastOp"=>#<BSON::Timestamp:0x007fded5a1c848 @seconds=1430431846, @increment=1>, "electionId"=><BSON::ObjectId:0x70297521798740 data=55429352e2bc3896d7ed9c2b>, "writeConcernError"=>{"code"=>100, "errmsg"=>"Not enough data-bearing nodes"}}
      ["code", 100]
      TypeError: no implicit conversion of String into Integer
      

      parse_single accesses doc as a hash which results in the TypeError when it's an Array as above.

      def parse_single(message, key, doc = document)
        if error = doc[key]
          append(message ,"#{error} (#{doc[CODE]})")
        end
      end
      

        Attachments

          Activity

            People

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            justincase Justin Case
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: