Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Leave a notice's second line out when Homebrew printed nothing
Țugui Dragoșcfc8397ad5e7
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 88dc2b8f..05f46425 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -61740,6 +61740,112 @@}}},+ "Homebrew stopped without saying why." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew se zastavil, aniž by uvedl důvod."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew hat den Vorgang abgebrochen, ohne einen Grund zu nennen."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew se ha detenido sin decir por qué."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew s’est arrêté sans indiquer pourquoi."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew si è interrotto senza dire perché."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrewは理由を報告せずに停止しました。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew가 이유를 알려 주지 않고 중단되었습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew is gestopt zonder te melden waarom."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew przerwał pracę bez podania przyczyny."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Homebrew parou sem dizer por quê."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew s‑a oprit fără a spune de ce."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew остановился, не сообщив причину."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew avslutades utan att säga varför."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew nedenini söylemeden durdu."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew зупинився, не пояснивши чому."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew已停止,但没有说明原因。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Homebrew已停止,但沒有說明原因。"+ }+ }+ }+ },"Homebrew suggests the %@ cask instead." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex e6cdfd40..ce388201 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -49,7 +49,7 @@ struct InventoryCommand: AsyncParsableCommand {/// Returns Homebrew's own Brewfile, or fails with why: an empty one would look like a success until someone/// uses it.private static func brewfile() async throws -> String {- let why: String+ let why: String?if !(await Homebrew.hasLocalDefinitions()) {why = noDefinitions(isInstalled: Homebrew.executableURL != nil, unrunnable: HomebrewChoice().unrunnable(),@@ -64,13 +64,16 @@ struct InventoryCommand: AsyncParsableCommand {} else {why = "Homebrew didn't say which version it is."}- throw CommandFailure("Homebrew didn't answer, so there is nothing to write a Brewfile from.\n\(why)")+ throw CommandFailure(+ ["Homebrew didn't answer, so there is nothing to write a Brewfile from.", why].compactMap(\.self)+ .joined(separator: "\n")+ )}/// Returns the packages Homebrew installed, so an app it installed says so. When Homebrew can't answer, the/// list goes on without it and says why.private static func casks() async -> [HomebrewPackage] {- let why: String+ let why: String?if await Homebrew.hasLocalDefinitions() {do {return try await Homebrew.installedPackages()@@ -92,8 +95,10 @@ struct InventoryCommand: AsyncParsableCommand {/// What a list other than a Brewfile says when Homebrew gave no packages: nothing on a Mac without Homebrew,/// and why otherwise.- static func homebrewNote(isInstalled: Bool, why: String) -> String? {- isInstalled ? "Homebrew didn't answer, so no app is marked as installed by it.\n\(why)" : nil+ static func homebrewNote(isInstalled: Bool, why: String?) -> String? {+ guard isInstalled else { return nil }+ return ["Homebrew didn't answer, so no app is marked as installed by it.", why].compactMap(\.self)+ .joined(separator: "\n")}/// Why Homebrew was not asked: without its local copy of the definitions it would download them. The copy isdiff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swiftindex 602c1435..beb5aecd 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift@@ -2,16 +2,19 @@ import Foundationimport PeelCoreenum CaskLookup {- /// The casks Homebrew knows and the installer receipts, with Homebrew's message when it failed. A failure is+ /// The casks Homebrew knows and the installer receipts, with how Homebrew failed when it did. A failure is/// kept apart from an empty list, which would wrongly say that no cask installed the app or has an update.struct Answer {var casks: [HomebrewPackage] = []/// Identifiers of the installer receipts on the Mac, used by the cask evidence and by the uninstall.var receipts: Set<String> = []- var failure: String?+ var failure: Homebrew.CommandFailure?var note: String? {- failure.map { "Homebrew didn't answer, so what only its casks know is missing.\n\($0)" }+ failure.map {+ ["Homebrew didn't answer, so what only its casks know is missing.", $0.output].compactMap(\.self)+ .joined(separator: "\n")+ }}}@@ -49,9 +52,9 @@ enum CaskLookup {}}- /// Returns what Homebrew printed when it failed, or else the error's description. It takes `any Error`- /// because a typed `throws(Homebrew.CommandFailure)` arrives as `any Error` through `async let`.- private static func why(_ error: any Error) -> String {- (error as? Homebrew.CommandFailure)?.output ?? error.localizedDescription+ /// Returns how Homebrew failed. It takes `any Error` because a typed `throws(Homebrew.CommandFailure)` arrives+ /// as `any Error` through `async let`.+ private static func why(_ error: any Error) -> Homebrew.CommandFailure {+ error as? Homebrew.CommandFailure ?? Homebrew.CommandFailure(output: error.localizedDescription)}}diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swiftindex 9b8c8d25..9fa48e12 100644--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift@@ -538,7 +538,12 @@ public enum Homebrew {public static let autoUpdateInterval: TimeInterval = 24 * 60 * 60public struct CommandFailure: Error, Sendable, Hashable {- public let output: String+ /// What Homebrew printed, or nil when it printed nothing but blank space.+ public let output: String?++ public init(output: String) {+ self.output = output.allSatisfy(\.isWhitespace) ? nil : output+ }}/// The `brew` executable: the one the person chose in Settings (`HomebrewChoice`), or else the one in either@@ -854,7 +859,7 @@ public enum Homebrew {} catch {// A failure is one sentence with no line ending, and the next call's report starts on a line of// its own.- output += error.output.hasSuffix("\n") ? error.output : error.output + "\n"+ if let said = error.output { output += said.hasSuffix("\n") ? said : said + "\n" }didFail = true}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swiftindex 136c84eb..e7a10b9e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift@@ -27,6 +27,15 @@ struct CommandLineTests {)}+ @Test func addsNothingAfterItsOwnSentenceWhenHomebrewPrintedNothing() {+ let silent = Homebrew.CommandFailure(output: "")+ #expect(+ InventoryCommand.homebrewNote(isInstalled: true, why: silent.output)+ == "Homebrew didn't answer, so no app is marked as installed by it."+ )+ #expect(CaskLookup.Answer(failure: silent).note == "Homebrew didn't answer, so what only its casks know is missing.")+ }+@Test func aListOfAppsSaysWhatItCouldNotRead() {let studio = URL(filePath: "/Volumes/Studio/Apps", directoryHint: .isDirectory)@@ -714,7 +723,10 @@ struct CommandLineTests {leftovers: [], unreadableLocations: [caches], cutShortLocations: [caches], needsFullDiskAccess: true)- let notes = UninstallCommand.whatStays(plan, app: app, homebrew: CaskLookup.Answer(failure: "brew is not installed"), scan: scan)+ let notes = UninstallCommand.whatStays(+ plan, app: app, homebrew: CaskLookup.Answer(failure: Homebrew.CommandFailure(output: "brew is not installed")),+ scan: scan+ )#expect(notes.count == 5)#expect(notes[0].hasPrefix("Homebrew didn't answer, so what only its casks know is missing."))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swiftindex 090c5f1e..222494c7 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift@@ -382,6 +382,30 @@ struct HomebrewTests {#expect(throws: Homebrew.CommandFailure.self) { try failed.transcript() }}+ @Test func aBrewThatFailsWithoutPrintingAnythingLeavesNoWords() {+ let silent = Homebrew.Attempt(status: 1, standardOutput: "", standardError: "\n")+ let failure = #expect(throws: Homebrew.CommandFailure.self) { try silent.answer() }+ #expect(failure?.output == nil)+ #expect(Homebrew.CommandFailure(output: " \t\n").output == nil)+ #expect(Homebrew.CommandFailure(output: "Error: No such keg\n").output == "Error: No such keg\n")+ }++ @Test func anUpgradeThatFailedWithoutAWordAddsNoEmptyLine() async {+ let packages = [+ HomebrewPackage(name: "wget", kind: .formula, installedVersion: "1.0"),+ HomebrewPackage(name: "firefox", kind: .cask, installedVersion: "1.0"),+ ]+ do {+ _ = try await Homebrew.upgrade(packages) { arguments throws(Homebrew.CommandFailure) in+ guard arguments[1] == "--cask" else { throw Homebrew.CommandFailure(output: "") }+ return Homebrew.Attempt(status: 0, standardOutput: "firefox was upgraded.\n", standardError: "")+ }+ Issue.record("a batch that failed read as a success")+ } catch {+ #expect(error.output == "firefox was upgraded.\n")+ }+ }+@Test func parsesInstalledFormulaeAndCasks() throws {let json = """{diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swiftindex a905b5a5..2873d103 100644--- a/Peel/Model/HomebrewLibrary.swift+++ b/Peel/Model/HomebrewLibrary.swift@@ -65,8 +65,8 @@ final class HomebrewLibrary {private(set) var unrunnableChoice = HomebrewChoice().unrunnable()/// A `brew` where Homebrew installs itself that another account owns or anyone can change, which Peel doesn't run.private(set) var refusedBrew = Homebrew.refusedInAUsualPlace()- /// Homebrew's output when the last reading failed, which is not the same as nothing being installed.- private(set) var couldNotRead: String?+ /// How the last reading failed, which is not the same as nothing being installed.+ private(set) var couldNotRead: Homebrew.CommandFailure?private(set) var packages: [HomebrewPackage]?/// The installed Homebrew's version and prefix. The version decides what Peel may ask it for.private(set) var installation: HomebrewInstallation?@@ -321,7 +321,7 @@ final class HomebrewLibrary {case .failure(let error):packages = packages ?? []hasAnswered = false- couldNotRead = error.output+ couldNotRead = error}self.installation = found// Keeps the last figure when this reading brought none: one that was right a moment ago beats none.@@ -510,7 +510,7 @@ final class HomebrewLibrary {}return CommandResult(succeeded: true, output: output)} catch {- return CommandResult(succeeded: false, output: error.output)+ return CommandResult(succeeded: false, output: error.output ?? "")}}@@ -587,7 +587,7 @@ final class HomebrewLibrary {case .success(let output):return CommandResult(succeeded: true, output: written.isEmpty ? output : written)case .failure(let failure):- return CommandResult(succeeded: false, output: written.isEmpty ? failure.output : written)+ return CommandResult(succeeded: false, output: written.isEmpty ? failure.output ?? "" : written)}}diff --git a/Peel/Model/InventoryExport.swift b/Peel/Model/InventoryExport.swiftindex 0ec19bd7..99fbf192 100644--- a/Peel/Model/InventoryExport.swift+++ b/Peel/Model/InventoryExport.swift@@ -31,6 +31,11 @@ enum InventoryExport {alert.runModal()}+ /// What the alert says when Homebrew couldn't write the Brewfile.+ static func reason(for failure: Homebrew.CommandFailure) -> String {+ failure.output ?? String(localized: "Homebrew stopped without saying why.")+ }+/// Returns nil when the file was written or the user canceled, and the error message otherwise.@MainActorprivate static func run(@@ -45,7 +50,7 @@ enum InventoryExport {do {brewfile = try await Homebrew.brewfile(from: installation)} catch {- return error.output+ return reason(for: error)}}let marking = casks(diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swiftindex d1010aa1..be08d15e 100644--- a/Peel/Views/Homebrew/HomebrewList.swift+++ b/Peel/Views/Homebrew/HomebrewList.swift@@ -469,13 +469,13 @@ struct HomebrewList: View {@ViewBuilderprivate var empty: some View {- if let problem = homebrew.couldNotRead {+ if let failure = homebrew.couldNotRead {Section {Notice(title: Text("Homebrew didn’t say what is installed"),- detail: Text(- verbatim: FixedSentence.translated(problem.trimmingCharacters(in: .whitespacesAndNewlines))- ),+ detail: failure.output.map {+ Text(verbatim: FixedSentence.translated($0.trimmingCharacters(in: .whitespacesAndNewlines)))+ },kind: .note) {}.listRowSeparator(.hidden)diff --git a/Peel/Views/Notice.swift b/Peel/Views/Notice.swiftindex dda1f351..090f43e6 100644--- a/Peel/Views/Notice.swift+++ b/Peel/Views/Notice.swift@@ -16,7 +16,8 @@ struct Notice<Actions: View>: View {}let title: Text- let detail: Text+ /// Nil when there is nothing to add, so the title stands alone in the middle of the panel.+ let detail: Text?var kind = Kind.problem/// A symbol to use instead of the default, such as the one a list row shows for the same fact.var systemImage: String?@@ -61,9 +62,11 @@ struct Notice<Actions: View>: View {title.font(isAlbum ? .system(size: 12.5, weight: .bold, design: .rounded) : .callout.weight(.semibold)).foregroundStyle(titleColor)- detail- .font(isAlbum ? .system(size: 11) : .caption)- .foregroundStyle(.secondary)+ if let detail {+ detail+ .font(isAlbum ? .system(size: 11) : .caption)+ .foregroundStyle(.secondary)+ }}}diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swiftindex 3d9ed029..85b71e1a 100644--- a/PeelTests/AppLibraryTests.swift+++ b/PeelTests/AppLibraryTests.swift@@ -696,6 +696,14 @@ private nonisolated final class TestClock: Sendable {#expect(none.casks.isEmpty && !none.didNotAnswer)}+ @Test func anExportSaysHomebrewStoppedWhenItPrintedNothing() {+ #expect(+ InventoryExport.reason(for: Homebrew.CommandFailure(output: "\n"))+ == String(localized: "Homebrew stopped without saying why.")+ )+ #expect(InventoryExport.reason(for: Homebrew.CommandFailure(output: "Error: No such keg")) == "Error: No such keg")+ }+@Test func twoCopiesOfAnAppAtTwoBuildsKeepAnAnswerEach() async throws {let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")defer { try? FileManager.default.removeItem(at: folder) }