diff --git a/Sources/Orders/Orders.docc/Orders.md b/Sources/Orders/Orders.docc/Orders.md index 9311362..952a12b 100644 --- a/Sources/Orders/Orders.docc/Orders.md +++ b/Sources/Orders/Orders.docc/Orders.md @@ -34,7 +34,3 @@ For information on Apple Wallet orders, see the [Apple Developer Documentation]( - ``OrderModel`` - ``OrdersRegistrationModel`` - ``OrderDataModel`` - -### Errors - -- ``OrdersError`` \ No newline at end of file diff --git a/Sources/Orders/OrdersError.swift b/Sources/Orders/OrdersError.swift deleted file mode 100644 index eee43c7..0000000 --- a/Sources/Orders/OrdersError.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// OrdersError.swift -// PassKit -// -// Created by Francesco Paolo Severino on 04/07/24. -// - -/// Errors that can be thrown by Apple Wallet orders. -public struct OrdersError: Error, Sendable { - /// The type of the errors that can be thrown by Apple Wallet orders. - public struct ErrorType: Sendable, Hashable, CustomStringConvertible { - enum Base: String, Sendable { - case noSourceFiles - case noOpenSSLExecutable - } - - let base: Base - - private init(_ base: Base) { - self.base = base - } - - /// The path for the source files is not a directory. - public static let noSourceFiles = Self(.noSourceFiles) - /// The `openssl` executable is missing. - public static let noOpenSSLExecutable = Self(.noOpenSSLExecutable) - - /// A textual representation of this error. - public var description: String { - base.rawValue - } - } - - private struct Backing: Sendable { - fileprivate let errorType: ErrorType - - init(errorType: ErrorType) { - self.errorType = errorType - } - } - - private var backing: Backing - - /// The type of this error. - public var errorType: ErrorType { backing.errorType } - - private init(errorType: ErrorType) { - self.backing = .init(errorType: errorType) - } - - /// The path for the source files is not a directory. - public static let noSourceFiles = Self(errorType: .noSourceFiles) - - /// The `openssl` executable is missing. - public static let noOpenSSLExecutable = Self(errorType: .noOpenSSLExecutable) -} - -extension OrdersError: CustomStringConvertible { - public var description: String { - "OrdersError(errorType: \(self.errorType))" - } -} diff --git a/Sources/Orders/OrdersServiceCustom.swift b/Sources/Orders/OrdersServiceCustom.swift index c6e50f9..3dde8f0 100644 --- a/Sources/Orders/OrdersServiceCustom.swift +++ b/Sources/Orders/OrdersServiceCustom.swift @@ -404,7 +404,7 @@ extension OrdersServiceCustom { // Swift Crypto doesn't support encrypted PEM private keys, so we have to use OpenSSL for that. if let pemPrivateKeyPassword { guard FileManager.default.fileExists(atPath: self.openSSLURL.path) else { - throw OrdersError.noOpenSSLExecutable + throw WalletError.noOpenSSLExecutable } let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) @@ -460,7 +460,7 @@ extension OrdersServiceCustom { guard (try? filesDirectory.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) ?? false else { - throw OrdersError.noSourceFiles + throw WalletError.noSourceFiles } let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) diff --git a/Sources/Passes/PassesError.swift b/Sources/PassKit/WalletError.swift similarity index 80% rename from Sources/Passes/PassesError.swift rename to Sources/PassKit/WalletError.swift index e93072b..6209a7a 100644 --- a/Sources/Passes/PassesError.swift +++ b/Sources/PassKit/WalletError.swift @@ -1,13 +1,13 @@ // -// PassesError.swift +// WalletError.swift // PassKit // // Created by Francesco Paolo Severino on 04/07/24. // -/// Errors that can be thrown by PassKit passes. -public struct PassesError: Error, Sendable, Equatable { - /// The type of the errors that can be thrown by PassKit passes. +/// Errors that can be thrown by Apple Wallet passes and orders. +public struct WalletError: Error, Sendable, Equatable { + /// The type of the errors that can be thrown by Apple Wallet passes and orders. public struct ErrorType: Sendable, Hashable, CustomStringConvertible, Equatable { enum Base: String, Sendable, Equatable { case noSourceFiles @@ -41,7 +41,7 @@ public struct PassesError: Error, Sendable, Equatable { self.errorType = errorType } - static func == (lhs: PassesError.Backing, rhs: PassesError.Backing) -> Bool { + static func == (lhs: WalletError.Backing, rhs: WalletError.Backing) -> Bool { lhs.errorType == rhs.errorType } } @@ -64,13 +64,13 @@ public struct PassesError: Error, Sendable, Equatable { /// The number of passes to bundle is invalid. public static let invalidNumberOfPasses = Self(errorType: .invalidNumberOfPasses) - public static func == (lhs: PassesError, rhs: PassesError) -> Bool { + public static func == (lhs: WalletError, rhs: WalletError) -> Bool { lhs.backing == rhs.backing } } -extension PassesError: CustomStringConvertible { +extension WalletError: CustomStringConvertible { public var description: String { - "PassesError(errorType: \(self.errorType))" + "WalletError(errorType: \(self.errorType))" } } diff --git a/Sources/Passes/Passes.docc/Passes.md b/Sources/Passes/Passes.docc/Passes.md index 19d5cab..3d3ed98 100644 --- a/Sources/Passes/Passes.docc/Passes.md +++ b/Sources/Passes/Passes.docc/Passes.md @@ -43,10 +43,6 @@ For information on Apple Wallet passes, see the [Apple Developer Documentation]( - ``PassesRegistrationModel`` - ``PassDataModel`` -### Errors - -- ``PassesError`` - ### Personalized Passes (⚠️ WIP) - diff --git a/Sources/Passes/PassesServiceCustom.swift b/Sources/Passes/PassesServiceCustom.swift index 34388e6..6c6fb31 100644 --- a/Sources/Passes/PassesServiceCustom.swift +++ b/Sources/Passes/PassesServiceCustom.swift @@ -450,7 +450,7 @@ extension PassesServiceCustom { // Swift Crypto doesn't support encrypted PEM private keys, so we have to use OpenSSL for that. if let pemPrivateKeyPassword { guard FileManager.default.fileExists(atPath: self.openSSLURL.path) else { - throw PassesError.noOpenSSLExecutable + throw WalletError.noOpenSSLExecutable } let dir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) @@ -506,7 +506,7 @@ extension PassesServiceCustom { guard (try? filesDirectory.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) ?? false else { - throw PassesError.noSourceFiles + throw WalletError.noSourceFiles } let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) @@ -558,7 +558,7 @@ extension PassesServiceCustom { /// - Returns: The bundle of passes as `Data`. public func build(passes: [P], on db: any Database) async throws -> Data { guard passes.count > 1 && passes.count <= 10 else { - throw PassesError.invalidNumberOfPasses + throw WalletError.invalidNumberOfPasses } var files: [ArchiveFile] = [] diff --git a/Tests/OrdersTests/OrdersTests.swift b/Tests/OrdersTests/OrdersTests.swift index ab61f1b..4d41358 100644 --- a/Tests/OrdersTests/OrdersTests.swift +++ b/Tests/OrdersTests/OrdersTests.swift @@ -393,10 +393,4 @@ struct OrdersTests { } } } - - @Test("OrdersError") - func ordersError() { - #expect(OrdersError.noSourceFiles.description == "OrdersError(errorType: noSourceFiles)") - #expect(OrdersError.noOpenSSLExecutable.description == "OrdersError(errorType: noOpenSSLExecutable)") - } } diff --git a/Tests/PassesTests/PassesTests.swift b/Tests/PassesTests/PassesTests.swift index fc6b7fa..9bc3637 100644 --- a/Tests/PassesTests/PassesTests.swift +++ b/Tests/PassesTests/PassesTests.swift @@ -66,7 +66,7 @@ struct PassesTests { do { let data = try await passesService.build(passes: [pass1], on: app.db) Issue.record("Expected error, got \(data)") - } catch let error as PassesError { + } catch let error as WalletError { #expect(error == .invalidNumberOfPasses) } } @@ -532,11 +532,14 @@ struct PassesTests { } } - @Test("PassesError") - func passesError() { - #expect(PassesError.noSourceFiles.description == "PassesError(errorType: noSourceFiles)") - #expect(PassesError.noOpenSSLExecutable.description == "PassesError(errorType: noOpenSSLExecutable)") - #expect(PassesError.invalidNumberOfPasses.description == "PassesError(errorType: invalidNumberOfPasses)") + @Test("WalletError") + func walletError() { + #expect(WalletError.noSourceFiles.description == "WalletError(errorType: noSourceFiles)") + #expect(WalletError.noOpenSSLExecutable.description == "WalletError(errorType: noOpenSSLExecutable)") + #expect(WalletError.invalidNumberOfPasses.description == "WalletError(errorType: invalidNumberOfPasses)") + + #expect(WalletError.noSourceFiles == WalletError.noSourceFiles) + #expect(WalletError.noOpenSSLExecutable != WalletError.invalidNumberOfPasses) } @Test("Default PassesDelegate Properties")