HotFix: Now Playing

This commit is contained in:
Hariharan Mudaliar 2026-03-07 20:19:18 +05:30
commit 07c0a7f0ae
No known key found for this signature in database
GPG key ID: 025583EB0BE5640E
2 changed files with 36 additions and 1 deletions

View file

@ -42,13 +42,23 @@ final class MediaChecker: Sendable {
let nowPlayingTestClientPath =
Bundle.main.bundleURL
.appendingPathComponent("Contents/Helpers/MediaRemoteAdapterTestClient")
.appendingPathComponent("Contents/Helpers/NowPlayingTestClient")
.path
guard FileManager.default.isExecutableFile(atPath: nowPlayingTestClientPath) else {
throw MediaCheckerError.missingResources
}
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/perl")
process.arguments = [scriptURL.path, frameworkPath, nowPlayingTestClientPath, "test"]
// Capture stderr to distinguish script errors from genuine deprecation.
// The perl script's fail() and the framework's test function both exit
// with status 1, but only script-level failures write to stderr.
let stderrPipe = Pipe()
process.standardError = stderrPipe
do {
try process.run()
} catch {
@ -81,6 +91,18 @@ final class MediaChecker: Sendable {
throw MediaCheckerError.timeout
}
let stderrData = stderrPipe.fileHandleForReading.readDataToEndOfFile()
let stderrOutput = String(data: stderrData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
// If the process exited with a non-zero status AND stderr contains
// output, a script-level error occurred (e.g. framework failed to load,
// symbol not found). Treat this as an execution failure rather than
// reporting deprecated, since perl's fail() also uses exit(1).
if process.terminationStatus != 0, !stderrOutput.isEmpty {
print("MediaChecker: script error (exit \(process.terminationStatus)): \(stderrOutput)")
throw MediaCheckerError.processExecutionFailed
}
let isDeprecated = process.terminationStatus == 1
return isDeprecated
}