Skip to content

Commit d83a14f

Browse files
committed
Rename errors
1 parent 9d7bd01 commit d83a14f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Sources/Basics/AuthorizationProvider.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public protocol AuthorizationProvider {
2424
}
2525

2626
public enum AuthorizationProviderError: Error {
27-
case noURLHost
27+
case invalidURLHost
2828
case notFound
29-
case unexpectedPasswordData
30-
case unexpectedError(String)
29+
case cannotEncodePassword
30+
case other(String)
3131
}
3232

3333
extension AuthorizationProvider {
@@ -63,7 +63,7 @@ public struct NetrcAuthorizationProvider: AuthorizationProvider {
6363

6464
public mutating func addOrUpdate(for url: Foundation.URL, user: String, password: String, callback: @escaping (Result<Void, Error>) -> Void) {
6565
guard let machineName = self.machineName(for: url) else {
66-
return callback(.failure(AuthorizationProviderError.noURLHost))
66+
return callback(.failure(AuthorizationProviderError.invalidURLHost))
6767
}
6868
let machine = TSCUtility.Netrc.Machine(name: machineName, login: user, password: password)
6969

@@ -89,12 +89,12 @@ public struct NetrcAuthorizationProvider: AuthorizationProvider {
8989
try self.saveToDisk(machines: machines)
9090
// At this point the netrc file should exist and non-empty
9191
guard let netrc = try Self.loadFromDisk(path: self.path) else {
92-
throw AuthorizationProviderError.unexpectedError("Failed to update netrc file at \(self.path)")
92+
throw AuthorizationProviderError.other("Failed to update netrc file at \(self.path)")
9393
}
9494
self.underlying = netrc
9595
callback(.success(()))
9696
} catch {
97-
callback(.failure(AuthorizationProviderError.unexpectedError("Failed to update netrc file at \(self.path): \(error)")))
97+
callback(.failure(AuthorizationProviderError.other("Failed to update netrc file at \(self.path): \(error)")))
9898
}
9999
}
100100

@@ -149,10 +149,10 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
149149

150150
public func addOrUpdate(for url: Foundation.URL, user: String, password: String, callback: @escaping (Result<Void, Error>) -> Void) {
151151
guard let server = self.server(for: url) else {
152-
return callback(.failure(AuthorizationProviderError.noURLHost))
152+
return callback(.failure(AuthorizationProviderError.invalidURLHost))
153153
}
154154
guard let passwordData = password.data(using: .utf8) else {
155-
return callback(.failure(AuthorizationProviderError.unexpectedPasswordData))
155+
return callback(.failure(AuthorizationProviderError.cannotEncodePassword))
156156
}
157157
let `protocol` = self.`protocol`(for: url)
158158

@@ -181,14 +181,14 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
181181
let passwordData = existingItem[kSecValueData as String] as? Data,
182182
let password = String(data: passwordData, encoding: String.Encoding.utf8),
183183
let account = existingItem[kSecAttrAccount as String] as? String else {
184-
throw AuthorizationProviderError.unexpectedError("Failed to extract credentials for server \(server) from keychain")
184+
throw AuthorizationProviderError.other("Failed to extract credentials for server \(server) from keychain")
185185
}
186186
return (user: account, password: password)
187187
} catch {
188188
switch error {
189189
case AuthorizationProviderError.notFound:
190190
ObservabilitySystem.topScope.emit(info: "No credentials found for server \(server) in keychain")
191-
case AuthorizationProviderError.unexpectedError(let detail):
191+
case AuthorizationProviderError.other(let detail):
192192
ObservabilitySystem.topScope.emit(error: detail)
193193
default:
194194
ObservabilitySystem.topScope.emit(error: "Failed to find credentials for server \(server) in keychain: \(error)")
@@ -206,7 +206,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
206206

207207
let status = SecItemAdd(query as CFDictionary, nil)
208208
guard status == errSecSuccess else {
209-
throw AuthorizationProviderError.unexpectedError("Failed to save credentials for server \(server) to keychain: status \(status)")
209+
throw AuthorizationProviderError.other("Failed to save credentials for server \(server) to keychain: status \(status)")
210210
}
211211
}
212212

@@ -222,7 +222,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
222222
throw AuthorizationProviderError.notFound
223223
}
224224
guard status == errSecSuccess else {
225-
throw AuthorizationProviderError.unexpectedError("Failed to update credentials for server \(server) in keychain: status \(status)")
225+
throw AuthorizationProviderError.other("Failed to update credentials for server \(server) in keychain: status \(status)")
226226
}
227227
}
228228

@@ -241,7 +241,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
241241
throw AuthorizationProviderError.notFound
242242
}
243243
guard status == errSecSuccess else {
244-
throw AuthorizationProviderError.unexpectedError("Failed to find credentials for server \(server) in keychain: status \(status)")
244+
throw AuthorizationProviderError.other("Failed to find credentials for server \(server) in keychain: status \(status)")
245245
}
246246

247247
return item

0 commit comments

Comments
 (0)