Skip to content

Commit beaac75

Browse files
committed
rebase leftovers
1 parent c23e9e8 commit beaac75

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

Sources/MongoSwift/BSON/BSONDecoder.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ extension _BSONDecoder {
360360
case .binary:
361361
let binary = try self.unboxCustom(value) { $0.binaryValue }
362362
guard let data = binary.data.getBytes(at: 0, length: binary.data.writerIndex) else {
363-
throw InternalError(message: "Cannot read \(binary.data.writerIndex) bytes from Binary.data")
363+
throw DecodingError.dataCorrupted(
364+
DecodingError.Context(
365+
codingPath: self.codingPath,
366+
debugDescription: "Cannot read \(binary.data.writerIndex) bytes from Binary.data"
367+
)
368+
)
364369
}
365370
return Data(data)
366371
case .base64:

Sources/MongoSwift/BSON/BSONDocument.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ extension BSONDocument {
145145
* presence first.
146146
*
147147
* - Throws:
148-
* - `InternalError` if the new value is an `Int` and cannot be written to BSON.
148+
* - `MongoError.InternalError` if the new value is an `Int` and cannot be written to BSON.
149149
* - `MongoError.LogicError` if the new value is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
150150
* - `MongoError.LogicError` if the new value is an `Array` and it contains a non-`BSONValue` element.
151-
* - `InternalError` if the underlying `bson_t` would exceed the maximum size by encoding this
151+
* - `MongoError.InternalError` if the underlying `bson_t` would exceed the maximum size by encoding this
152152
* key-value pair.
153153
*/
154154
internal mutating func setValue(for key: String, to newValue: BSON, checkForKey: Bool = true) throws {
@@ -210,7 +210,7 @@ extension BSONDocument {
210210
/// Retrieves the value associated with `for` as a `BSON?`, which can be nil if the key does not exist in the
211211
/// `BSONDocument`.
212212
///
213-
/// - Throws: `InternalError` if the BSON buffer is too small (< 5 bytes).
213+
/// - Throws: `MongoError.InternalError` if the BSON buffer is too small (< 5 bytes).
214214
internal func getValue(for key: String) throws -> BSON? {
215215
guard let iter = BSONDocumentIterator(over: self) else {
216216
throw BSONDocument.BSONBufferTooSmallError

Sources/MongoSwift/BSON/BSONDocumentIterator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class BSONDocumentIterator: IteratorProtocol {
102102
/// Returns the current value (equivalent to the `currentValue` property) or throws on error.
103103
///
104104
/// - Throws:
105-
/// - `InternalError` if the current value of this `BSONDocumentIterator` cannot be decoded to BSON.
105+
/// - `MongoError.InternalError` if the current value of this `BSONDocumentIterator` cannot be decoded to BSON.
106106
internal func safeCurrentValue() throws -> BSON {
107107
guard let bsonType = BSONDocumentIterator.bsonTypeMap[currentType] else {
108108
throw MongoError.InternalError(
@@ -177,7 +177,7 @@ public class BSONDocumentIterator: IteratorProtocol {
177177
* Overwrites the current value of this `BSONDocumentIterator` with the supplied value.
178178
*
179179
* - Throws:
180-
* - `InternalError` if the new value is an `Int` and cannot be written to BSON.
180+
* - `MongoError.InternalError` if the new value is an `Int` and cannot be written to BSON.
181181
* - `MongoError.LogicError` if the new value is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
182182
*/
183183
internal func overwriteCurrentValue(with newValue: Overwritable) throws {

Sources/MongoSwift/BSON/BSONValue.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal protocol BSONValue: Codable {
7070
* - key: A `String`, the key under which to store the value.
7171
*
7272
* - Throws:
73-
* - `InternalError` if the `DocumentStorage` would exceed the maximum size by encoding this
73+
* - `MongoError.InternalError` if the `DocumentStorage` would exceed the maximum size by encoding this
7474
* key-value pair.
7575
* - `MongoError.LogicError` if the value is an `Array` and it contains a non-`BSONValue` element.
7676
*/
@@ -240,18 +240,18 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
240240

241241
/// Initializes a `Subtype` with a custom value. This value must be in the range 0x80-0xFF.
242242
/// - Throws:
243-
/// - `InvalidArgumentError` if value passed is outside of the range 0x80-0xFF
243+
/// - `MongoError.InvalidArgumentError` if value passed is outside of the range 0x80-0xFF
244244
public static func userDefined(_ value: Int) throws -> Subtype {
245245
guard let byteValue = UInt8(exactly: value) else {
246-
throw InvalidArgumentError(message: "Cannot represent \(value) as UInt8")
246+
throw MongoError.InvalidArgumentError(message: "Cannot represent \(value) as UInt8")
247247
}
248248
guard byteValue >= 0x80 else {
249-
throw InvalidArgumentError(
249+
throw MongoError.InvalidArgumentError(
250250
message: "userDefined value must be greater than or equal to 0x80 got \(byteValue)"
251251
)
252252
}
253253
guard let subtype = Subtype(rawValue: byteValue) else {
254-
throw InvalidArgumentError(message: "Cannot represent \(byteValue) as Subtype")
254+
throw MongoError.InvalidArgumentError(message: "Cannot represent \(byteValue) as Subtype")
255255
}
256256
return subtype
257257
}
@@ -360,7 +360,7 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
360360
}
361361

362362
guard let data = self.data.getBytes(at: 0, length: 16) else {
363-
throw InternalError(message: "Unable to read 16 bytes from Binary.data")
363+
throw MongoError.InternalError(message: "Unable to read 16 bytes from Binary.data")
364364
}
365365

366366
let uuid: uuid_t = (
@@ -524,7 +524,7 @@ public struct BSONDecimal128: BSONValue, Equatable, Codable, CustomStringConvert
524524
* - a BSONDecimal128 number as a string.
525525
*
526526
* - Throws:
527-
* - A `InvalidArgumentError` if the string does not represent a BSONDecimal128 encodable value.
527+
* - A `MongoError.InvalidArgumentError` if the string does not represent a BSONDecimal128 encodable value.
528528
*
529529
* - SeeAlso: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst
530530
*/
@@ -862,11 +862,11 @@ public struct BSONObjectID: BSONValue, Equatable, CustomStringConvertible, Codab
862862

863863
/// Initializes an `BSONObjectID` from the provided hex `String`.
864864
/// - Throws:
865-
/// - `InvalidArgumentError` if string passed is not a valid BSONObjectID
865+
/// - `MongoError.InvalidArgumentError` if string passed is not a valid BSONObjectID
866866
/// - SeeAlso: https://github.com/mongodb/specifications/blob/master/source/objectid.rst
867867
public init(_ hex: String) throws {
868868
guard bson_oid_is_valid(hex, hex.utf8.count) else {
869-
throw InvalidArgumentError(message: "Cannot create ObjectId from \(hex)")
869+
throw MongoError.InvalidArgumentError(message: "Cannot create ObjectId from \(hex)")
870870
}
871871
var oid_t = bson_oid_t()
872872
bson_oid_init_from_string(&oid_t, hex)

Sources/MongoSwift/BSON/Overwritable.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ internal protocol Overwritable: BSONValue {
88
*
99
* - Throws:
1010
* - `MongoError.InternalError` if the `BSONValue` is an `Int` and cannot be written to BSON.
11-
* - `MongoError.LogicError` if the `BSONValue` is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
11+
* - `MongoError.LogicError` if the `BSONValue` is a `BSONDecimal128` or `BSONObjectID` and is improperly
12+
* formatted.
1213
*/
1314
func writeToCurrentPosition(of iter: BSONDocumentIterator) throws
1415
}

Sources/MongoSwift/MongoCollection+BulkWrite.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public struct BulkWriteResult: Decodable {
401401
* - insertedIDs: Map of inserted IDs
402402
*
403403
* - Throws:
404-
* - `InternalError` if an unexpected error occurs reading the reply from the server.
404+
* - `MongoError.InternalError` if an unexpected error occurs reading the reply from the server.
405405
*/
406406
fileprivate init?(reply: BSONDocument, insertedIDs: [Int: BSON]) throws {
407407
guard reply.keys.contains(where: { MongocKeys(rawValue: $0) != nil }) else {

Sources/MongoSwift/MongoError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private func extractWriteConcernError(from reply: BSONDocument) throws -> MongoE
472472

473473
/// Internal function used by write methods performing single writes that are implemented via the bulk API. If the
474474
/// provided error is not a `MongoError.BulkWriteError`, it will be returned as-is. Otherwise, the error will be
475-
/// converted to a `MongoError.WriteError`. If conversion fails, an `InternalError` will be returned.
475+
/// converted to a `MongoError.WriteError`. If conversion fails, an `MongoError.InternalError` will be returned.
476476
internal func convertBulkWriteError(_ error: Error) -> Error {
477477
guard let bwe = error as? MongoError.BulkWriteError else {
478478
return error

Sources/TestsCommon/CommonTestUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ extension BSONDocument {
148148
* - `T`: Any type conforming to the `BSONValue` protocol
149149
* - Returns: The value stored under key, as type `T`
150150
* - Throws:
151-
* - `InternalError` if the value cannot be cast to type `T` or is not in the `Document`, or an
151+
* - `MongoError.InternalError` if the value cannot be cast to type `T` or is not in the `Document`, or an
152152
* unexpected error occurs while decoding the `BSONValue`.
153153
*
154154
*/

0 commit comments

Comments
 (0)