Fix exception mapping with exit codes

- Migitates changed behaviour in boot how exceptions are
  handled thus caused trouble with exit code mappings
  on a shell side.
- Fixes #961
This commit is contained in:
Janne Valkealahti
2023-12-24 08:49:33 +00:00
parent cb8f44ff63
commit 51f49f7567
2 changed files with 11 additions and 3 deletions

View File

@@ -59,7 +59,11 @@ public class ExitCodeAutoConfiguration {
@Override
public int getExitCode(Throwable exception) {
if (exception.getCause() instanceof CommandExecution.CommandParserExceptionsException) {
// for e vs. its cause, see gh-961
if (exception instanceof CommandExecution.CommandParserExceptionsException) {
return 2;
}
else if (exception.getCause() instanceof CommandExecution.CommandParserExceptionsException) {
return 2;
}
// only map parsing error so that other mappers can do their job
@@ -83,7 +87,11 @@ public class ExitCodeAutoConfiguration {
public int getExitCode(Throwable exception) {
int exitCode = 0;
for (Function<Throwable, Integer> function : functions) {
Integer code = function.apply(exception.getCause());
Throwable cause = exception.getCause();
if (cause == null) {
cause = exception;
}
Integer code = function.apply(cause);
if (code != null) {
if (code > 0 && code > exitCode || code < 0 && code < exitCode) {
exitCode = code;

View File

@@ -1080,7 +1080,7 @@ public interface CommandRegistration {
@Override
public ExitCodeSpec map(Class<? extends Throwable> e, int code) {
Function<Throwable, Integer> f = t -> {
if (ObjectUtils.nullSafeEquals(t.getClass(), e)) {
if (t != null && ObjectUtils.nullSafeEquals(t.getClass(), e)) {
return code;
}
return 0;