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

Support Exit codes from thrown CustomNSError conformers #244

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refs #243 - introduce customnserror support, so exit code is calculat…
…ed correctly
  • Loading branch information
SergeyPetrachkov committed Oct 2, 2020
commit 831e19ff4cdb90cb6d54206188f2e3d19e2bf278
13 changes: 13 additions & 0 deletions Sources/ArgumentParser/Usage/MessageInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ enum MessageInfo {
self.init(error: CommandError(commandStack: [type.asCommand], parserError: e), type: type)
return

case let e as CustomNSError:
// Send ParserErrors back through the CommandError path
self.init(
error: CommandError(
commandStack: [type.asCommand],
parserError: .userValidationError(e)
),
type: type
)
return

default:
commandStack = [type.asCommand]
// if the error wasn't one of our two Error types, wrap it as a userValidationError
Expand Down Expand Up @@ -92,6 +103,8 @@ enum MessageInfo {
}
case let error as ExitCode:
self = .other(message: "", exitCode: error.rawValue)
case let error as CustomNSError:
self = .other(message: error.localizedDescription, exitCode: Int32(error.errorCode))
case let error as LocalizedError where error.errorDescription != nil:
self = .other(message: error.errorDescription!, exitCode: EXIT_FAILURE)
default:
Expand Down