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

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.1.0
    • Component/s: None
    • Labels:
      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

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: