From 84798601cd563f5314dd46375c73613a3b4e9c0a Mon Sep 17 00:00:00 2001 From: Eliseo Martelli Date: Sat, 14 Jun 2025 02:07:55 +0200 Subject: [PATCH] Throw errors in ServiceManager (#188) --- Sources/ContainerPlugin/ServiceManager.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/ContainerPlugin/ServiceManager.swift b/Sources/ContainerPlugin/ServiceManager.swift index d7a936f3..8c5710d1 100644 --- a/Sources/ContainerPlugin/ServiceManager.swift +++ b/Sources/ContainerPlugin/ServiceManager.swift @@ -62,21 +62,23 @@ public struct ServiceManager { let null = FileHandle.nullDevice let stdoutPipe = Pipe() + let stderrPipe = Pipe() launchctl.standardOutput = stdoutPipe - launchctl.standardError = null + launchctl.standardError = stderrPipe try launchctl.run() let outputData = stdoutPipe.fileHandleForReading.readDataToEndOfFile() + let stderrData = stderrPipe.fileHandleForReading.readDataToEndOfFile() launchctl.waitUntilExit() let status = launchctl.terminationStatus guard status == 0 else { - // TODO: review error handling - return [] + throw ContainerizationError( + .internalError, message: "Command `launchctl list` failed with status \(status). Message: \(String(data: stderrData, encoding: .utf8) ?? "No error message")") } guard let outputText = String(data: outputData, encoding: .utf8) else { - // TODO: review error handling - return [] + throw ContainerizationError( + .internalError, message: "Could not decode output of command `launchctl list`. Message: \(String(data: stderrData, encoding: .utf8) ?? "No error message")") } // The third field of each line of launchctl list output is the label