Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

recovery: a failed winetricks step says the script's own reason up front (highball#135)

Gauthier Piarrette4bdea0ac1eb9
diff --git a/Sources/HighballKit/Recovery.swift b/Sources/HighballKit/Recovery.swift
index c1da751..5f4d1db 100644
--- a/Sources/HighballKit/Recovery.swift
+++ b/Sources/HighballKit/Recovery.swift
@@ -53,14 +53,17 @@ public struct Recovery: Equatable, Sendable {
return Recovery(headline: "The Windows environment didn't finish setting up.",
meaning: "Highball can run the setup again.",
actionTitle: "Repair", action: .repairBottle)
- case let .processFailed(command, _, _) where command.contains("winetricks"):
+ case let .processFailed(command, _, output) where command.contains("winetricks"):
// The command is "/bin/bash <winetricks> --unattended <verbs>": naming bash helps
// nobody (highball#135 read "/bin/bash didn't finish" and offered a fresh download).
let words = command.split(separator: " ").map(String.init)
let verbs = words.drop(while: { $0 != "--unattended" }).dropFirst().joined(separator: " ")
let what = verbs.isEmpty ? "The winetricks step" : "Installing \(verbs) with winetricks"
- return Recovery(headline: "\(what) didn't finish.",
- meaning: "It downloads its files from the internet as it runs, and those servers refuse now and then, so trying again in a few minutes often works. Details has the reason it gave.",
+ // The reason is the script's own last line, and asking for it under Details cost
+ // #135 two rounds with nothing pasted back. Say it up front.
+ var meaning = "It downloads its files from the internet as it runs, and those servers refuse now and then, so trying again in a few minutes often works."
+ if let reason = Self.winetricksReason(output) { meaning += " It said: \(reason)" }
+ return Recovery(headline: "\(what) didn't finish.", meaning: meaning,
actionTitle: "Try again", action: .retry)
case let .processFailed(command, _, _):
let name = command.split(separator: " ").first.map(String.init) ?? "The installer"
@@ -78,3 +81,16 @@ public struct Recovery: Equatable, Sendable {
}
}
}
+
+
+extension Recovery {
+ /// The last line of a winetricks run that says something, skipping its progress noise and
+ /// the shell's own "exited with" footer. Nil when the output is empty.
+ static func winetricksReason(_ output: String) -> String? {
+ let noise = ["warning: taskset", "Executing", "------", "[mvk-", "fixme:", "exited with"]
+ let lines = output.split(separator: "\n").map { $0.trimmingCharacters(in: .whitespaces) }
+ return lines.last { line in
+ !line.isEmpty && !noise.contains { line.hasPrefix($0) || line.contains($0) }
+ }.map { String($0.prefix(200)) }
+ }
+}
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index 744a0a7..60bb257 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -1123,6 +1123,12 @@ extension RegressionTests {
XCTAssertEqual(tricks.action, .retry)
XCTAssertEqual(tricks.headline, "Installing corefonts with winetricks didn't finish.", "not '/bin/bash didn't finish' (highball#135)")
XCTAssertFalse(tricks.meaning.contains("fresh copy"))
+ XCTAssertFalse(tricks.meaning.contains("It said"), "no reason line when winetricks printed nothing")
+ // The reason is the script's own last real line, ahead of asking for Details (highball#135).
+ let out = "warning: taskset/cpuset not available on your platform!\nExecuting mkdir -p /e/cache\n------------------------------------------------------\nwarning: /usr/bin/curl failed to download arial32.exe: SourceForge returned 503\n------------------------------------------------------\n"
+ let said = Recovery.describe(HighballError.processFailed(command: "/bin/bash /e/tools/winetricks --unattended corefonts", status: 1, output: out))
+ XCTAssertTrue(said.meaning.hasSuffix("It said: warning: /usr/bin/curl failed to download arial32.exe: SourceForge returned 503"), said.meaning)
+ XCTAssertNil(Recovery.winetricksReason("Executing x\n------\n"), "noise-only output gives no reason")
let wow = Recovery.describe(HighballError.invalid("Windows 32-bit support couldn't be set up in this bottle"))
XCTAssertEqual(wow.action, .repairBottle)
let net = Recovery.describe(URLError(.timedOut))