Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2026-01-15 11:11:51 -06:00
parent ae161dfd18
commit 347212ad89
6 changed files with 35 additions and 33 deletions

View File

@ -1,23 +0,0 @@
{
"pins" : [
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "swift-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-testing.git",
"state" : {
"revision" : "399f76dcd91e4c688ca2301fa24a8cc6d9927211",
"version" : "0.99.0"
}
}
],
"version" : 2
}

View File

@ -15,9 +15,7 @@ let package = Package(
targets: ["LocalData"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-testing.git", from: "0.7.0")
],
dependencies: [],
targets: [
.target(
name: "LocalData"
@ -25,8 +23,7 @@ let package = Package(
.testTarget(
name: "LocalDataTests",
dependencies: [
"LocalData",
.product(name: "Testing", package: "swift-testing")
"LocalData"
]
),
]

View File

@ -207,7 +207,7 @@ actor FileStorageHelper {
)
} catch {
Logger.error("Failed to create directory", error: error)
throw StorageError.fileError(error)
throw StorageError.fileError(error.localizedDescription)
}
}
@ -222,7 +222,7 @@ actor FileStorageHelper {
Logger.debug("Successfully wrote \(data.count) bytes to \(url.lastPathComponent)")
} catch {
Logger.error("Failed to write to \(url.path)", error: error)
throw StorageError.fileError(error)
throw StorageError.fileError(error.localizedDescription)
}
}

View File

@ -22,9 +22,11 @@ public enum KeychainAccessibility: Sendable, CaseIterable {
/// Item is always accessible, regardless of device lock state.
/// Least secure - use only when absolutely necessary.
@available(iOS, deprecated: 12.0, message: "Use an accessibility level that provides some user protection, such as afterFirstUnlock")
case always
/// Item is always accessible but not migrated to new devices.
@available(iOS, deprecated: 12.0, message: "Use an accessibility level that provides some user protection, such as afterFirstUnlockThisDeviceOnly")
case alwaysThisDeviceOnly
/// Item is only accessible when the device has a passcode set.

View File

@ -1,10 +1,10 @@
import Foundation
public enum StorageError: Error {
public enum StorageError: Error, Equatable {
case serializationFailed, deserializationFailed
case securityApplicationFailed
case keychainError(OSStatus)
case fileError(Error)
case fileError(String) // Changed from Error to String for easier Equatable conformance
case phoneOnlyKeyAccessedOnWatch(String)
case watchOnlyKeyAccessedOnPhone(String)
case invalidUserDefaultsSuite(String)
@ -14,6 +14,32 @@ public enum StorageError: Error {
case unregisteredKey(String)
case duplicateRegisteredKeys([String])
case missingDescription(String)
public static func == (lhs: StorageError, rhs: StorageError) -> Bool {
switch (lhs, rhs) {
case (.serializationFailed, .serializationFailed),
(.deserializationFailed, .deserializationFailed),
(.securityApplicationFailed, .securityApplicationFailed),
(.dataTooLargeForSync, .dataTooLargeForSync),
(.notFound, .notFound):
return true
case (.keychainError(let l), .keychainError(let r)):
return l == r
case (.fileError(let l), .fileError(let r)):
return l == r
case (.phoneOnlyKeyAccessedOnWatch(let l), .phoneOnlyKeyAccessedOnWatch(let r)),
(.watchOnlyKeyAccessedOnPhone(let l), .watchOnlyKeyAccessedOnPhone(let r)),
(.invalidUserDefaultsSuite(let l), .invalidUserDefaultsSuite(let r)),
(.invalidAppGroupIdentifier(let l), .invalidAppGroupIdentifier(let r)),
(.unregisteredKey(let l), .unregisteredKey(let r)),
(.missingDescription(let l), .missingDescription(let r)):
return l == r
case (.duplicateRegisteredKeys(let l), .duplicateRegisteredKeys(let r)):
return l == r
default:
return false
}
}
}
extension StorageError: @unchecked Sendable {}

View File

@ -56,7 +56,7 @@ struct LocalDataTests {
#expect(fetched == storedValue)
try await StorageRouter.shared.remove(key)
await #expect(throws: StorageError.notFound) {
#expect(throws: StorageError.notFound) {
_ = try await StorageRouter.shared.get(key)
}
}