Improve errors.

Partial #313

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2024-10-23 14:11:52 -04:00
parent 06ee9608be
commit 53c64b1758
No known key found for this signature in database
6 changed files with 10 additions and 8 deletions

View file

@ -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)
}
}
}

View file

@ -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)
}
}
}

View file

@ -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."

View file

@ -78,7 +78,7 @@ public class UninstallSpec: QuickSpec {
expect {
try uninstall.run(appLibrary: mockLibrary)
}
.to(throwError(MASError.uninstallFailed))
.to(throwError(MASError.uninstallFailed(error: nil)))
}
}
}

View file

@ -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!

View file

@ -114,7 +114,7 @@ class MASErrorTestCase: XCTestCase {
}
func testUninstallFailed() {
error = .uninstallFailed
error = .uninstallFailed(error: nil)
XCTAssertEqual(error.description, "Uninstall failed")
}