2017-04-30 16:16:52 -05:00
|
|
|
//
|
|
|
|
|
// AppError.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 30/4/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
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
|
|
|
|
|
case gitReset
|
|
|
|
|
case gitCreateSignature
|
|
|
|
|
case gitPushNotSuccessful
|
|
|
|
|
case passwordEntity
|
|
|
|
|
case pgpPublicKeyNotFound(keyID: String)
|
|
|
|
|
case pgpPrivateKeyNotFound(keyID: String)
|
|
|
|
|
case keyExpiredOrIncompatible
|
|
|
|
|
case wrongPassphrase
|
|
|
|
|
case wrongPasswordFilename
|
|
|
|
|
case decryption
|
|
|
|
|
case encryption
|
|
|
|
|
case encoding
|
|
|
|
|
case unknown
|
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)
|
2019-01-20 13:08:29 +01:00
|
|
|
default:
|
|
|
|
|
return localizationKey.localize()
|
|
|
|
|
}
|
2017-04-30 16:16:52 -05:00
|
|
|
}
|
|
|
|
|
}
|