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)
|
||||
}
|
||||
} 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)")
|
||||
}
|
||||
} catch {
|
||||
printError("Unable to move app to trash.")
|
||||
throw MASError.uninstallFailed
|
||||
throw MASError.uninstallFailed(error: error as NSError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ enum MASError: Error, Equatable {
|
|||
case noVendorWebsite
|
||||
|
||||
case notInstalled(appID: AppID)
|
||||
case uninstallFailed
|
||||
case uninstallFailed(error: NSError?)
|
||||
case macOSUserMustBeRoot
|
||||
|
||||
case noData
|
||||
|
@ -83,7 +83,10 @@ extension MASError: CustomStringConvertible {
|
|||
return "App does not have a vendor website"
|
||||
case .notInstalled(let 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"
|
||||
case .macOSUserMustBeRoot:
|
||||
return "Apps installed from the Mac App Store require root permission to remove."
|
||||
|
|
|
@ -78,7 +78,7 @@ public class UninstallSpec: QuickSpec {
|
|||
expect {
|
||||
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
|
||||
if app.bundlePath == "/dev/null" {
|
||||
throw MASError.uninstallFailed
|
||||
throw MASError.uninstallFailed(error: nil)
|
||||
}
|
||||
|
||||
// Success is the default, watch out for false positives!
|
||||
|
|
|
@ -114,7 +114,7 @@ class MASErrorTestCase: XCTestCase {
|
|||
}
|
||||
|
||||
func testUninstallFailed() {
|
||||
error = .uninstallFailed
|
||||
error = .uninstallFailed(error: nil)
|
||||
XCTAssertEqual(error.description, "Uninstall failed")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue