Skip to content

Added exit code to message for exitedWithNonZeroStatus error #23

@macblazer

Description

@macblazer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions