mas/MasKit/MASError.swift

83 lines
2.1 KiB
Swift
Raw Normal View History

//
// Error.swift
// mas-cli
//
// Created by Andrew Naylor on 21/08/2015.
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
//
2018-02-11 22:30:59 +00:00
import Foundation
public enum MASError: Error, CustomStringConvertible, Equatable {
2016-09-17 12:58:38 +00:00
case notSignedIn
case signInDisabled
2016-09-25 21:13:23 +00:00
case signInFailed(error: NSError?)
2016-09-17 12:58:38 +00:00
case alreadySignedIn
2016-09-25 21:13:23 +00:00
case purchaseFailed(error: NSError?)
case downloadFailed(error: NSError?)
case noDownloads
case cancelled
2016-09-25 21:13:23 +00:00
case searchFailed
case noSearchResultsFound
2018-12-27 21:01:48 +00:00
case notInstalled
case uninstallFailed
public var description: String {
2016-09-25 21:13:23 +00:00
switch self {
case .notSignedIn:
return "Not signed in"
case .signInDisabled:
return "The 'signin' command has been disabled on this macOS version. " +
2018-08-12 21:09:58 +00:00
"Please sign into the Mac App Store app manually." +
"\nFor more info see: " +
2018-08-12 21:09:58 +00:00
"https://github.com/mas-cli/mas/issues/164"
case .signInFailed(let error):
2016-09-25 21:13:23 +00:00
if let error = error {
return "Sign in failed: \(error.localizedDescription)"
} else {
return "Sign in failed"
}
2016-09-25 21:13:23 +00:00
case .alreadySignedIn:
return "Already signed in"
case .purchaseFailed(let error):
2016-09-25 21:13:23 +00:00
if let error = error {
return "Download request failed: \(error.localizedDescription)"
} else {
return "Download request failed"
}
case .downloadFailed(let error):
2016-09-25 21:13:23 +00:00
if let error = error {
return "Download failed: \(error.localizedDescription)"
} else {
return "Download failed"
}
2016-09-25 21:13:23 +00:00
case .noDownloads:
return "No downloads began"
2016-09-25 21:13:23 +00:00
case .cancelled:
return "Download cancelled"
2016-09-25 21:13:23 +00:00
case .searchFailed:
return "Search failed"
2016-09-25 21:13:23 +00:00
case .noSearchResultsFound:
2018-12-27 21:01:48 +00:00
return "No results found"
case .notInstalled:
return "Not installed"
case .uninstallFailed:
return "Uninstall failed"
2016-09-25 21:13:23 +00:00
}
}
}