Fix ArgumentParser's exception printing (#367)

This commit is contained in:
Nikolay Edigaryev 2022-12-21 18:06:01 +04:00 committed by GitHub
parent 1380ece108
commit ba4f00fa78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -96,21 +96,19 @@ struct Root: AsyncParsableCommand {
try command.run()
}
} catch {
if exitCode(for: error).rawValue == 0 {
exit(withError: error)
}
// Capture the error into Sentry
SentrySDK.capture(error: error)
SentrySDK.flush(timeout: 2.seconds.timeInterval)
print(error)
// Handle a non-ArgumentParser's exception that requires a specific exit code to be set
if let errorWithExitCode = error as? HasExitCode {
print(error)
Foundation.exit(errorWithExitCode.exitCode)
}
Foundation.exit(1)
// Handle any other exception, including ArgumentParser's ones
exit(withError: error)
}
}