Skip to content

Cause exception not printed by default execution exception handler #1048

@remkop

Description

@remkop

When an exception occurs in the business logic, this is handled by the execution exception handler. By default, this prints the full stack trace of the exception.

Since 4.3.0, only the stack trace of the "outer" exception is printed. If that exception has any "cause" exceptions, these are incorrectly omitted.

With the work done in #484, #845 and #1008 (colors in exception handler), we no longer call exception.printStackTrace() but instead have a custom implementation that has the same effect but uses ANSI colors. This implementation incorrectly omits the stack trace for any nested "cause" exceptions (and their nested cause, if any).

A workaround is to register a custom execution exception handler as follows:

new CommandLine(new MyApp())
        .setExecutionExceptionHandler(
            (Exception ex, CommandLine commandLine, ParseResult parseResult) -> {
                        ex.printStackTrace();
                        return commandLine.getCommandSpec().exitCodeOnExecutionException();
            })
        .execute(args);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions