diff --git a/Sources/mas/Commands/Uninstall.swift b/Sources/mas/Commands/Uninstall.swift index 4e1e591..9d7c3a9 100644 --- a/Sources/mas/Commands/Uninstall.swift +++ b/Sources/mas/Commands/Uninstall.swift @@ -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) } } } diff --git a/Sources/mas/Controllers/MasAppLibrary.swift b/Sources/mas/Controllers/MasAppLibrary.swift index cb3b45f..7554d3c 100644 --- a/Sources/mas/Controllers/MasAppLibrary.swift +++ b/Sources/mas/Controllers/MasAppLibrary.swift @@ -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) } } } diff --git a/Sources/mas/Errors/MASError.swift b/Sources/mas/Errors/MASError.swift index 4eba734..564afb6 100644 --- a/Sources/mas/Errors/MASError.swift +++ b/Sources/mas/Errors/MASError.swift @@ -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." diff --git a/Tests/masTests/Commands/UninstallSpec.swift b/Tests/masTests/Commands/UninstallSpec.swift index c2587fc..dd342a0 100644 --- a/Tests/masTests/Commands/UninstallSpec.swift +++ b/Tests/masTests/Commands/UninstallSpec.swift @@ -78,7 +78,7 @@ public class UninstallSpec: QuickSpec { expect { try uninstall.run(appLibrary: mockLibrary) } - .to(throwError(MASError.uninstallFailed)) + .to(throwError(MASError.uninstallFailed(error: nil))) } } } diff --git a/Tests/masTests/Controllers/AppLibraryMock.swift b/Tests/masTests/Controllers/AppLibraryMock.swift index b2a9215..e4daad1 100644 --- a/Tests/masTests/Controllers/AppLibraryMock.swift +++ b/Tests/masTests/Controllers/AppLibraryMock.swift @@ -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! diff --git a/Tests/masTests/Errors/MASErrorTestCase.swift b/Tests/masTests/Errors/MASErrorTestCase.swift index 06e1649..47c83d6 100644 --- a/Tests/masTests/Errors/MASErrorTestCase.swift +++ b/Tests/masTests/Errors/MASErrorTestCase.swift @@ -114,7 +114,7 @@ class MASErrorTestCase: XCTestCase { } func testUninstallFailed() { - error = .uninstallFailed + error = .uninstallFailed(error: nil) XCTAssertEqual(error.description, "Uninstall failed") }