Skip to content

Commit 1725e73

Browse files
committed
wip
1 parent caced54 commit 1725e73

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Sources/MongoSwift/BSON/BSONDecoder.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,16 @@ public class BSONDecoder {
142142
return doc
143143
}
144144
let _decoder = _BSONDecoder(referencing: .document(document), options: self.options)
145-
return try type.init(from: _decoder)
145+
do {
146+
return try type.init(from: _decoder)
147+
} catch let error as BSONErrorProtocol {
148+
throw DecodingError.dataCorrupted(
149+
DecodingError.Context(
150+
codingPath: [],
151+
debugDescription: "Unable to decode BSON \(error.errorDescription ?? "")"
152+
)
153+
)
154+
}
146155
}
147156

148157
/**
@@ -532,7 +541,7 @@ private struct _BSONKeyedDecodingContainer<K: CodingKey>: KeyedDecodingContainer
532541
/// Private helper function to check for a value in self.container. Returns the value stored
533542
/// under `key`, or throws an error if the value is not found.
534543
private func getValue(forKey key: Key) throws -> BSON {
535-
guard let entry = (try convertingBSONErrors { try self.container.getValue(for: key.stringValue) }) else {
544+
guard let entry = try self.container.getValue(for: key.stringValue) else {
536545
throw DecodingError.keyNotFound(
537546
key,
538547
DecodingError.Context(

0 commit comments

Comments
 (0)