Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-379

Improve error message for type mismatches when decoding driver introduced BSON types

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 0.1.0
    • None
    • None

    Description

      Right now, we throw an error returned from bsonDecodingDirectly when encountering a _BSONEncoder in the decoder initializers for driver introduced BSON types. We do this so that e.g. decoder.decode(ObjectId.self, from: doc) will throw a nice error, but we're throwing the same error in the following case:

      struct A: Codable {
          let a: ObjectId
      }
      try BSONDecoder().decode(A.self, from: ["a": "asdfasdf"]) // will call through to ObjectId.init
      

      which doesn't make sense. We should update this to throw a better error message in the latter case.

      Attachments

        Activity

          People

            patrick.freed@mongodb.com Patrick Freed
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: