Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exit code to message for exitedWithNonZeroStatus error #23

Open
macblazer opened this issue Jan 5, 2024 · 0 comments
Open

Added exit code to message for exitedWithNonZeroStatus error #23

macblazer opened this issue Jan 5, 2024 · 0 comments

Comments

@macblazer
Copy link
Contributor

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):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant