The SubprocessError type nicely encapsulates the errors that come from the (deprecated) Shell code. However, when the process being called exits with a non-zero exit code and output no other info to stdout or stderr, the description of the error is empty for the calling code.
Example code:
do {
_ = try Shell(["/usr/bin/false"]).exec()
} catch {
os_log("Error description was: '\(error.localizedDescription)'")
if let exitError = error as? SubprocessError,
case .exitedWithNonZeroStatus(let exitCode, let text) = exitError {
os_log("Exit code was: \(exitCode); text was '\(text)'")
}
}
Actual output:
Error description was: ''
Exit code was: 1; text was ''
Expected output (something like this):
Error description was: 'Process exited with code 1'
Exit code was: 1; text was ''
Current usages of . exitedWithNonZeroStatus:
|
throw SubprocessError.exitedWithNonZeroStatus(exitCode, message ?? "") |
|
throw SubprocessError.exitedWithNonZeroStatus(exitCode, text) |
Current code that converts the error to text:
|
case .exitedWithNonZeroStatus(_, let errorMessage): |
The
SubprocessErrortype nicely encapsulates the errors that come from the (deprecated)Shellcode. However, when the process being called exits with a non-zero exit code and output no other info to stdout or stderr, the description of the error is empty for the calling code.Example code:
Actual output:
Expected output (something like this):
Current usages of . exitedWithNonZeroStatus:
Subprocess/Sources/Subprocess/Shell.swift
Line 110 in 5568e42
Subprocess/Sources/Subprocess/Shell.swift
Line 154 in 5568e42
Current code that converts the error to text:
Subprocess/Sources/Subprocess/Errors.swift
Line 55 in 5568e42