Throw errors in ServiceManager (#188)

This commit is contained in:
Eliseo Martelli
2025-06-13 17:07:55 -07:00
committed by GitHub
parent 05798f38a1
commit 84798601cd
+7 -5
View File
@@ -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