Skip to content

Conversation

@natecook1000
Copy link
Member

@natecook1000 natecook1000 commented Mar 2, 2020

Description

This adds an ExitCode error type that stores an exit code, and updates the exit machinery (1) to use ExitCode as the source for exit codes, and (2) to silently exit when the provided error is an ExitCode instance.

New API:

/// An error type that only includes an exit code.
///
/// If you're printing custom errors messages yourself, you can throw this error
/// to specify the exit code without adding any additional output to standard
/// out or standard error.
public struct ExitCode: Error {
   /// Creates a new `ExitCode` with the given code.
   public init(_ code: Int32)

   /// An exit code that indicates successful completion of a command.
   public static let success

   /// An exit code that indicates that the command failed.
   public static let failure

   /// An exit code that indicates that the user provided invalid input.
   public static let validationFailure
}

Documentation Plan

Included API documentation and expanded a section in the Validation & Errors guide.

Test Plan

Added tests for failing silently and for exiting with each preset error code and a custom error code.

Source Impact

The new type is an additive change. There's an additional behavior change that I'd call a bug fix, where errors that convert to an empty string now don't print the "Error:" prefix by itself.

This adds an `ExitCode` error type that stores an exit code,
and updates the exit machinery to (1) use `ExitCode` as the source
for exit codes, and (2) silently exit when the provided error
is an `ExitCode` instance.
@mpapple-swift mpapple-swift self-requested a review March 4, 2020 18:45
@natecook1000 natecook1000 merged commit 9ebf401 into master Mar 4, 2020
@natecook1000 natecook1000 deleted the nate/exitcode_type branch March 4, 2020 19:10
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

Successfully merging this pull request may close these issues.

4 participants