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

Provide clear exception message when trying to serialize types to BSON that do not define serialization behavior

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.9.4
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Fully Compatible

      Currently if one tries to serialize an array or hash to bson which contains values that are not serializable, they get a less than informative exception:

      irb(main):006:0> [1..4].to_bson
      Traceback (most recent call last):
              6: from /home/w/.rbenv/versions/2.7/bin/irb:23:in `<main>'
              5: from /home/w/.rbenv/versions/2.7/bin/irb:23:in `load'
              4: from /home/w/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
              3: from (irb):6
              2: from /home/w/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bson-4.9.3/lib/bson/array.rb:45:in `to_bson'
              1: from /home/w/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bson-4.9.3/lib/bson/array.rb:45:in `put_array'
      NoMethodError (undefined method `bson_type' for 1..4:Range)
      

      The exception should specifically state that an unserializable type is attempted to be serialized.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: