EG-69 - fixed bug with picocli that was causing uncaught exception's stacktrace to always be printed on stderr (#5985)

calling `picocli.CommandLine.AbstractHandler#andExit` causes the exception handler to forcefully terminate the program execution (calling `java.lang.System#exit`) at all costs, even in case of `ExecutionException` being throw by `picocli.CommandLine#parseWithHandlers(picocli.CommandLine.IParseResultHandler2<R>, picocli.CommandLine.IExceptionHandler2<R>, java.lang.String...)`, this was causing the program to always print the exception stack trace on the `stderr` and terminating even before entering the `catch` block from lines 85 to 93
This commit is contained in:
Walter Oggioni 2020-02-26 09:49:14 +00:00 committed by GitHub
parent 4ea74a45b5
commit 92a437f333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,9 +70,9 @@ fun CordaCliWrapper.start(args: Array<String>) {
} else {
Help.Ansi.AUTO
}
@Suppress("SpreadOperator")
val results = cmd.parseWithHandlers(RunLast().useOut(System.out).useAnsi(defaultAnsiMode),
DefaultExceptionHandler<List<Any>>().useErr(System.err).useAnsi(defaultAnsiMode).andExit(ExitCodes.FAILURE),
*args)
DefaultExceptionHandler<List<Any>>().useErr(System.err).useAnsi(defaultAnsiMode), *args)
// If an error code has been returned, use this and exit
results?.firstOrNull()?.let {
if (it is Int) {