Skip to content

Throwing a CustomNSError should exit with the custom error code #243

Closed
@natecook1000

Description

If you throw an error type that conforms to CustomNSError from the run method or a validation closure, the exit code of the program should be the one given by the custom error type's errorCode property.

ArgumentParser version: main branch
Swift version: Apple Swift version 5.3

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

Build and run this command, then use echo $? (or echo $status in fish) to inspect the exit code:

import ArgumentParser
import Foundation

enum CustomError: CustomNSError {
  case error
  
  var errorCode: Int {
    switch self {
    case .error: return 7
    }
  }
}

struct Example: ParsableCommand {
  func run() throws {
    throw CustomError.error
  }
}

Example.main()

Expected behavior

The exit code should be 7.

Actual behavior

It's actually 1, aka EXIT_FAILURE.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions