2017-04-30 16:16:52 -05:00
|
|
|
//
|
|
|
|
|
// AppError.swift
|
2021-08-28 07:32:31 +02:00
|
|
|
// passKit
|
2017-04-30 16:16:52 -05:00
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 30/4/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2022-01-09 21:38:39 -08:00
|
|
|
import Foundation
|
|
|
|
|
|
2019-06-29 23:09:24 +02:00
|
|
|
public enum AppError: Error, Equatable {
|
2020-09-20 15:07:18 +02:00
|
|
|
case repositoryNotSet
|
|
|
|
|
case repositoryRemoteBranchNotFound(branchName: String)
|
|
|
|
|
case repositoryBranchNotFound(branchName: String)
|
|
|
|
|
case keyImport
|
|
|
|
|
case readingFile(fileName: String)
|
|
|
|
|
case passwordDuplicated
|
2026-03-09 22:16:15 +01:00
|
|
|
case cannotDeleteNonEmptyDirectory
|
2020-09-20 15:07:18 +02:00
|
|
|
case gitReset
|
2025-02-02 22:18:16 -08:00
|
|
|
case gitCommit
|
2020-09-20 15:07:18 +02:00
|
|
|
case gitCreateSignature
|
|
|
|
|
case gitPushNotSuccessful
|
|
|
|
|
case pgpPublicKeyNotFound(keyID: String)
|
|
|
|
|
case pgpPrivateKeyNotFound(keyID: String)
|
2022-01-09 21:38:39 -08:00
|
|
|
case yubiKey(YubiKeyError)
|
|
|
|
|
case passwordFileNotFound(path: String)
|
2020-09-20 15:07:18 +02:00
|
|
|
case keyExpiredOrIncompatible
|
|
|
|
|
case wrongPassphrase
|
|
|
|
|
case wrongPasswordFilename
|
|
|
|
|
case decryption
|
|
|
|
|
case encryption
|
|
|
|
|
case encoding
|
2022-01-09 21:38:39 -08:00
|
|
|
case other(message: String)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum YubiKeyError: Error, Equatable {
|
|
|
|
|
case connection(message: String)
|
|
|
|
|
case selectApplication(message: String)
|
|
|
|
|
case verify(message: String)
|
|
|
|
|
case decipher(message: String)
|
2024-12-15 21:08:27 -08:00
|
|
|
case other(message: String)
|
2022-01-09 21:38:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension YubiKeyError: LocalizedError {
|
|
|
|
|
public var errorDescription: String? {
|
|
|
|
|
switch self {
|
2024-12-15 21:08:27 -08:00
|
|
|
case let .connection(message), let .decipher(message), let .other(message), let .selectApplication(message), let .verify(message):
|
2022-01-09 21:38:39 -08:00
|
|
|
return message
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-11 22:55:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension AppError: LocalizedError {
|
|
|
|
|
public var errorDescription: String? {
|
2020-09-20 15:07:18 +02:00
|
|
|
let enumName = String(describing: self)
|
|
|
|
|
let localizationKey = "\(enumName.first!.uppercased())\(enumName.dropFirst().prefix { $0 != "(" })Error."
|
2019-01-20 13:08:29 +01:00
|
|
|
switch self {
|
2020-12-18 10:03:47 +01:00
|
|
|
case let .readingFile(name), let .repositoryBranchNotFound(name), let .repositoryRemoteBranchNotFound(name):
|
2019-01-20 13:08:29 +01:00
|
|
|
return localizationKey.localize(name)
|
2020-12-18 10:03:47 +01:00
|
|
|
case let .pgpPrivateKeyNotFound(keyID), let .pgpPublicKeyNotFound(keyID):
|
2020-04-14 20:20:16 -07:00
|
|
|
return localizationKey.localize(keyID)
|
2024-12-15 21:08:27 -08:00
|
|
|
case let .yubiKey(error):
|
|
|
|
|
return error.errorDescription
|
2022-01-09 21:38:39 -08:00
|
|
|
case let .other(message):
|
|
|
|
|
return message.localize()
|
2019-01-20 13:08:29 +01:00
|
|
|
default:
|
|
|
|
|
return localizationKey.localize()
|
|
|
|
|
}
|
2017-04-30 16:16:52 -05:00
|
|
|
}
|
|
|
|
|
}
|