mirror of
https://github.com/mas-cli/mas
synced 2024-11-24 20:43:10 +00:00
Improve errors.
Partial #313 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
parent
06ee9608be
commit
53c64b1758
6 changed files with 10 additions and 8 deletions
|
@ -44,7 +44,7 @@ extension Mas {
|
||||||
try appLibrary.uninstallApp(app: installedApp)
|
try appLibrary.uninstallApp(app: installedApp)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
throw MASError.uninstallFailed
|
throw error as? MASError ?? MASError.uninstallFailed(error: error as NSError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,7 @@ class MasAppLibrary: AppLibrary {
|
||||||
printInfo("App moved to trash: \(path)")
|
printInfo("App moved to trash: \(path)")
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
printError("Unable to move app to trash.")
|
throw MASError.uninstallFailed(error: error as NSError)
|
||||||
throw MASError.uninstallFailed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ enum MASError: Error, Equatable {
|
||||||
case noVendorWebsite
|
case noVendorWebsite
|
||||||
|
|
||||||
case notInstalled(appID: AppID)
|
case notInstalled(appID: AppID)
|
||||||
case uninstallFailed
|
case uninstallFailed(error: NSError?)
|
||||||
case macOSUserMustBeRoot
|
case macOSUserMustBeRoot
|
||||||
|
|
||||||
case noData
|
case noData
|
||||||
|
@ -83,7 +83,10 @@ extension MASError: CustomStringConvertible {
|
||||||
return "App does not have a vendor website"
|
return "App does not have a vendor website"
|
||||||
case .notInstalled(let appID):
|
case .notInstalled(let appID):
|
||||||
return "No apps installed with app ID \(appID)"
|
return "No apps installed with app ID \(appID)"
|
||||||
case .uninstallFailed:
|
case .uninstallFailed(let error):
|
||||||
|
if let error {
|
||||||
|
return "Uninstall failed: \(error.localizedDescription)"
|
||||||
|
}
|
||||||
return "Uninstall failed"
|
return "Uninstall failed"
|
||||||
case .macOSUserMustBeRoot:
|
case .macOSUserMustBeRoot:
|
||||||
return "Apps installed from the Mac App Store require root permission to remove."
|
return "Apps installed from the Mac App Store require root permission to remove."
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class UninstallSpec: QuickSpec {
|
||||||
expect {
|
expect {
|
||||||
try uninstall.run(appLibrary: mockLibrary)
|
try uninstall.run(appLibrary: mockLibrary)
|
||||||
}
|
}
|
||||||
.to(throwError(MASError.uninstallFailed))
|
.to(throwError(MASError.uninstallFailed(error: nil)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class AppLibraryMock: AppLibrary {
|
||||||
|
|
||||||
// Special case for testing where we pretend the trash command failed
|
// Special case for testing where we pretend the trash command failed
|
||||||
if app.bundlePath == "/dev/null" {
|
if app.bundlePath == "/dev/null" {
|
||||||
throw MASError.uninstallFailed
|
throw MASError.uninstallFailed(error: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success is the default, watch out for false positives!
|
// Success is the default, watch out for false positives!
|
||||||
|
|
|
@ -114,7 +114,7 @@ class MASErrorTestCase: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testUninstallFailed() {
|
func testUninstallFailed() {
|
||||||
error = .uninstallFailed
|
error = .uninstallFailed(error: nil)
|
||||||
XCTAssertEqual(error.description, "Uninstall failed")
|
XCTAssertEqual(error.description, "Uninstall failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue