Skip to content

Commit

Permalink
Unify error types
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Dec 1, 2024
1 parent bb90049 commit 1ea069c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 95 deletions.
4 changes: 0 additions & 4 deletions Sources/Orders/Orders.docc/Orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ For information on Apple Wallet orders, see the [Apple Developer Documentation](
- ``OrderModel``
- ``OrdersRegistrationModel``
- ``OrderDataModel``

### Errors

- ``OrdersError``
62 changes: 0 additions & 62 deletions Sources/Orders/OrdersError.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/Orders/OrdersServiceCustom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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))"
}
}
4 changes: 0 additions & 4 deletions Sources/Passes/Passes.docc/Passes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ For information on Apple Wallet passes, see the [Apple Developer Documentation](
- ``PassesRegistrationModel``
- ``PassDataModel``

### Errors

- ``PassesError``

### Personalized Passes (⚠️ WIP)

- <doc:Personalization>
Expand Down
6 changes: 3 additions & 3 deletions Sources/Passes/PassesServiceCustom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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] = []
Expand Down
6 changes: 0 additions & 6 deletions Tests/OrdersTests/OrdersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,4 @@ struct OrdersTests {
}
}
}

@Test("OrdersError")
func ordersError() {
#expect(OrdersError.noSourceFiles.description == "OrdersError(errorType: noSourceFiles)")
#expect(OrdersError.noOpenSSLExecutable.description == "OrdersError(errorType: noOpenSSLExecutable)")
}
}
15 changes: 9 additions & 6 deletions Tests/PassesTests/PassesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 1ea069c

Please sign in to comment.