Skip to content

Commit c23e9e8

Browse files
committed
update docs to use new error types
1 parent 45ed95a commit c23e9e8

33 files changed

+430
-411
lines changed

Guides/Error-Handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The possible errors that conform to `MongoServerError` are as follows:
3232
- `MongoError.BulkWriteError`
3333
- Thrown when the server returns errors as part of an executed bulk write.
3434
- If WriteConcernFailure is populated, writeErrors may not be.
35-
- **Note:** `InsertMany` throws a `BulkWriteError`, _not_ a `WriteError`.
35+
- **Note:** `InsertMany` throws a `MongoError.BulkWriteError`, _not_ a `MongoError.WriteError`.
3636

3737

3838
### User Errors

Sources/MongoSwift/BSON/BSONDocument.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ extension BSONDocument {
146146
*
147147
* - Throws:
148148
* - `InternalError` if the new value is an `Int` and cannot be written to BSON.
149-
* - `LogicError` if the new value is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
150-
* - `LogicError` if the new value is an `Array` and it contains a non-`BSONValue` element.
149+
* - `MongoError.LogicError` if the new value is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
150+
* - `MongoError.LogicError` if the new value is an `Array` and it contains a non-`BSONValue` element.
151151
* - `InternalError` if the underlying `bson_t` would exceed the maximum size by encoding this
152152
* key-value pair.
153153
*/
@@ -373,7 +373,7 @@ extension BSONDocument {
373373
* - Returns: the parsed `BSONDocument`
374374
*
375375
* - Throws:
376-
* - A `InvalidArgumentError` if the data passed in is invalid JSON.
376+
* - A `MongoError.InvalidArgumentError` if the data passed in is invalid JSON.
377377
*/
378378
public init(fromJSON: Data) throws {
379379
self._storage = Storage(stealing: try fromJSON.withUnsafeBytePointer { bytes in
@@ -391,7 +391,7 @@ extension BSONDocument {
391391

392392
/// Convenience initializer for constructing a `BSONDocument` from a `String`.
393393
/// - Throws:
394-
/// - A `InvalidArgumentError` if the string passed in is invalid JSON.
394+
/// - A `MongoError.InvalidArgumentError` if the string passed in is invalid JSON.
395395
public init(fromJSON json: String) throws {
396396
// `String`s are Unicode under the hood so force unwrap always succeeds.
397397
// see https://www.objc.io/blog/2018/02/13/string-to-data-and-back/
@@ -401,9 +401,9 @@ extension BSONDocument {
401401
/**
402402
* Constructs a `BSONDocument` from raw BSON `Data`.
403403
* - Throws:
404-
* - A `InvalidArgumentError` if `bson` is too short or too long to be valid BSON.
405-
* - A `InvalidArgumentError` if the first four bytes of `bson` do not contain `bson.count`.
406-
* - A `InvalidArgumentError` if the final byte of `bson` is not a null byte.
404+
* - A `MongoError.InvalidArgumentError` if `bson` is too short or too long to be valid BSON.
405+
* - A `MongoError.InvalidArgumentError` if the first four bytes of `bson` do not contain `bson.count`.
406+
* - A `MongoError.InvalidArgumentError` if the final byte of `bson` is not a null byte.
407407
* - SeeAlso: http://bsonspec.org/
408408
*/
409409
public init(fromBSON bson: Data) throws {

Sources/MongoSwift/BSON/BSONDocumentIterator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public class BSONDocumentIterator: IteratorProtocol {
178178
*
179179
* - Throws:
180180
* - `InternalError` if the new value is an `Int` and cannot be written to BSON.
181-
* - `LogicError` if the new value is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
181+
* - `MongoError.LogicError` if the new value is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
182182
*/
183183
internal func overwriteCurrentValue(with newValue: Overwritable) throws {
184184
let newValueType = type(of: newValue).bsonType

Sources/MongoSwift/BSON/BSONValue.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ internal protocol BSONValue: Codable {
7272
* - Throws:
7373
* - `InternalError` if the `DocumentStorage` would exceed the maximum size by encoding this
7474
* key-value pair.
75-
* - `LogicError` if the value is an `Array` and it contains a non-`BSONValue` element.
75+
* - `MongoError.LogicError` if the value is an `Array` and it contains a non-`BSONValue` element.
7676
*/
7777
func encode(to document: inout BSONDocument, forKey key: String) throws
7878

7979
/**
8080
* Given a `BSONDocumentIterator` known to have a next value of this type,
8181
* initializes the value.
8282
*
83-
* - Throws: `LogicError` if the current type of the `BSONDocumentIterator` does not correspond to the
83+
* - Throws: `MongoError.LogicError` if the current type of the `BSONDocumentIterator` does not correspond to the
8484
* associated type of this `BSONValue`.
8585
*/
8686
static func from(iterator iter: BSONDocumentIterator) throws -> BSON
@@ -259,7 +259,7 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
259259

260260
/// Initializes a `BSONBinary` instance from a `UUID`.
261261
/// - Throws:
262-
/// - `InvalidArgumentError` if a `BSONBinary` cannot be constructed from this UUID.
262+
/// - `MongoError.InvalidArgumentError` if a `BSONBinary` cannot be constructed from this UUID.
263263
public init(from uuid: UUID) throws {
264264
let uuidt = uuid.uuid
265265

@@ -275,7 +275,7 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
275275

276276
/// Initializes a `BSONBinary` instance from a `Data` object and a `UInt8` subtype.
277277
/// - Throws:
278-
/// - `InvalidArgumentError` if the provided data is incompatible with the specified subtype.
278+
/// - `MongoError.InvalidArgumentError` if the provided data is incompatible with the specified subtype.
279279
public init(data: Data, subtype: Subtype) throws {
280280
if [Subtype.uuid, Subtype.uuidDeprecated].contains(subtype) && data.count != 16 {
281281
throw MongoError.InvalidArgumentError(
@@ -291,7 +291,7 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
291291

292292
/// Initializes a `BSONBinary` instance from a base64 `String` and a `Subtype`.
293293
/// - Throws:
294-
/// - `InvalidArgumentError` if the base64 `String` is invalid or if the provided data is
294+
/// - `MongoError.InvalidArgumentError` if the base64 `String` is invalid or if the provided data is
295295
/// incompatible with the specified subtype.
296296
public init(base64: String, subtype: Subtype) throws {
297297
guard let dataObj = Data(base64Encoded: base64) else {
@@ -315,7 +315,7 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
315315
let subtype = bson_subtype_t(UInt32(self.subtype.rawValue))
316316
let length = self.data.writerIndex
317317
guard let byteArray = self.data.getBytes(at: 0, length: length) else {
318-
throw InternalError(message: "Cannot read \(length) bytes from Binary.data")
318+
throw MongoError.InternalError(message: "Cannot read \(length) bytes from Binary.data")
319319
}
320320
try document.withMutableBSONPointer { docPtr in
321321
guard bson_append_binary(docPtr, key, Int32(key.utf8.count), subtype, byteArray, UInt32(length)) else {
@@ -351,7 +351,7 @@ public struct BSONBinary: BSONValue, Equatable, Codable, Hashable {
351351

352352
/// Converts this `BSONBinary` instance to a `UUID`.
353353
/// - Throws:
354-
/// - `InvalidArgumentError` if a non-UUID subtype is set on this `BSONBinary`.
354+
/// - `MongoError.InvalidArgumentError` if a non-UUID subtype is set on this `BSONBinary`.
355355
public func toUUID() throws -> UUID {
356356
guard [Subtype.uuid, Subtype.uuidDeprecated].contains(self.subtype) else {
357357
throw MongoError.InvalidArgumentError(
@@ -554,7 +554,7 @@ public struct BSONDecimal128: BSONValue, Equatable, Codable, CustomStringConvert
554554
/// Returns the provided string as a `bson_decimal128_t`, or throws an error if initialization fails due an
555555
/// invalid string.
556556
/// - Throws:
557-
/// - `InvalidArgumentError` if the parameter string does not correspond to a valid `BSONDecimal128`.
557+
/// - `MongoError.InvalidArgumentError` if the parameter string does not correspond to a valid `BSONDecimal128`.
558558
internal static func toLibBSONType(_ str: String) throws -> bson_decimal128_t {
559559
var value = bson_decimal128_t()
560560
guard bson_decimal128_from_string(str, &value) else {

Sources/MongoSwift/BSON/Overwritable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ internal protocol Overwritable: BSONValue {
77
* Overwrites the value at the current position of the iterator with self.
88
*
99
* - Throws:
10-
* - `InternalError` if the `BSONValue` is an `Int` and cannot be written to BSON.
11-
* - `LogicError` if the `BSONValue` is a `BSONDecimal128` or `BSONObjectID` and is improperly formatted.
10+
* - `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.
1212
*/
1313
func writeToCurrentPosition(of iter: BSONDocumentIterator) throws
1414
}

Sources/MongoSwift/ChangeStream.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ public class ChangeStream<T: Codable>: CursorProtocol {
152152
* met, potentially after multiple requests to the server.
153153
*
154154
* If the future evaluates to an error, it is likely one of the following:
155-
* - `CommandError` if an error occurs while fetching more results from the server.
156-
* - `LogicError` if this function is called after the change stream has died.
157-
* - `LogicError` if this function is called and the session associated with this change stream is inactive.
155+
* - `MongoError.CommandError` if an error occurs while fetching more results from the server.
156+
* - `MongoError.LogicError` if this function is called after the change stream has died.
157+
* - `MongoError.LogicError` if this function is called and the session associated with this change stream is
158+
* inactive.
158159
* - `DecodingError` if an error occurs decoding the server's response.
159160
*/
160161
public func next() -> EventLoopFuture<T?> {
@@ -179,9 +180,10 @@ public class ChangeStream<T: Codable>: CursorProtocol {
179180
* there was no data.
180181
*
181182
* If the future evaluates to an error, it is likely one of the following:
182-
* - `CommandError` if an error occurs while fetching more results from the server.
183-
* - `LogicError` if this function is called after the change stream has died.
184-
* - `LogicError` if this function is called and the session associated with this change stream is inactive.
183+
* - `MongoError.CommandError` if an error occurs while fetching more results from the server.
184+
* - `MongoError.LogicError` if this function is called after the change stream has died.
185+
* - `MongoError.LogicError` if this function is called and the session associated with this change stream is
186+
* inactive.
185187
* - `DecodingError` if an error occurs decoding the server's response.
186188
*/
187189
public func tryNext() -> EventLoopFuture<T?> {
@@ -203,9 +205,10 @@ public class ChangeStream<T: Codable>: CursorProtocol {
203205
* An `EventLoopFuture<[T]>` evaluating to the results currently available in this change stream, or an error.
204206
*
205207
* If the future evaluates to an error, that error is likely one of the following:
206-
* - `CommandError` if an error occurs while fetching more results from the server.
207-
* - `LogicError` if this function is called after the change stream has died.
208-
* - `LogicError` if this function is called and the session associated with this change stream is inactive.
208+
* - `MongoError.CommandError` if an error occurs while fetching more results from the server.
209+
* - `MongoError.LogicError` if this function is called after the change stream has died.
210+
* - `MongoError.LogicError` if this function is called and the session associated with this change stream is
211+
* inactive.
209212
* - `DecodingError` if an error occurs decoding the server's responses.
210213
*/
211214
public func toArray() -> EventLoopFuture<[T]> {
@@ -230,9 +233,10 @@ public class ChangeStream<T: Codable>: CursorProtocol {
230233
* encountered.
231234
*
232235
* If the future evaluates to an error, that error is likely one of the following:
233-
* - `CommandError` if an error occurs while fetching more results from the server.
234-
* - `LogicError` if this function is called after the change stream has died.
235-
* - `LogicError` if this function is called and the session associated with this change stream is inactive.
236+
* - `MongoError.CommandError` if an error occurs while fetching more results from the server.
237+
* - `MongoError.LogicError` if this function is called after the change stream has died.
238+
* - `MongoError.LogicError` if this function is called and the session associated with this change stream is
239+
* inactive.
236240
* - `DecodingError` if an error occurs decoding the server's responses.
237241
*/
238242
public func forEach(_ body: @escaping (T) throws -> Void) -> EventLoopFuture<Void> {

Sources/MongoSwift/ClientSession.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public final class ClientSession {
325325

326326
/// Appends this provided session to an options document for libmongoc interoperability.
327327
/// - Throws:
328-
/// - `LogicError` if this session is inactive
328+
/// - `MongoError.LogicError` if this session is inactive
329329
internal func append(to doc: inout BSONDocument) throws {
330330
guard case let .started(session, _) = self.state else {
331331
throw ClientSession.SessionInactiveError
@@ -360,9 +360,9 @@ public final class ClientSession {
360360
* An `EventLoopFuture<Void>` that succeeds when `startTransaction` is successful.
361361
*
362362
* If the future fails, the error is likely one of the following:
363-
* - `CommandError` if an error occurs that prevents the command from executing.
364-
* - `LogicError` if the session already has an in-progress transaction.
365-
* - `LogicError` if `startTransaction` is called on an ended session.
363+
* - `MongoError.CommandError` if an error occurs that prevents the command from executing.
364+
* - `MongoError.LogicError` if the session already has an in-progress transaction.
365+
* - `MongoError.LogicError` if `startTransaction` is called on an ended session.
366366
*
367367
* - SeeAlso:
368368
* - https://docs.mongodb.com/manual/core/transactions/
@@ -384,9 +384,9 @@ public final class ClientSession {
384384
* An `EventLoopFuture<Void>` that succeeds when `commitTransaction` is successful.
385385
*
386386
* If the future fails, the error is likely one of the following:
387-
* - `CommandError` if an error occurs that prevents the command from executing.
388-
* - `LogicError` if the session has no in-progress transaction.
389-
* - `LogicError` if `commitTransaction` is called on an ended session.
387+
* - `MongoError.CommandError` if an error occurs that prevents the command from executing.
388+
* - `MongoError.LogicError` if the session has no in-progress transaction.
389+
* - `MongoError.LogicError` if `commitTransaction` is called on an ended session.
390390
*
391391
* - SeeAlso:
392392
* - https://docs.mongodb.com/manual/core/transactions/
@@ -408,8 +408,8 @@ public final class ClientSession {
408408
* An `EventLoopFuture<Void>` that succeeds when `abortTransaction` is successful.
409409
*
410410
* If the future fails, the error is likely one of the following:
411-
* - `LogicError` if the session has no in-progress transaction.
412-
* - `LogicError` if `abortTransaction` is called on an ended session.
411+
* - `MongoError.LogicError` if the session has no in-progress transaction.
412+
* - `MongoError.LogicError` if `abortTransaction` is called on an ended session.
413413
*
414414
* - SeeAlso:
415415
* - https://docs.mongodb.com/manual/core/transactions/

0 commit comments

Comments
 (0)