Skip to content

Commit 52c607d

Browse files
committed
Fix incorrectly wrapped exceptions
1 parent 929f96e commit 52c607d

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "io.github.vaperion.blade"
9-
version = "1.1.2"
9+
version = "1.1.3"
1010

1111
subprojects {
1212
apply(plugin = "io.freefair.lombok")

core/src/main/java/me/vaperion/blade/impl/executor/CommandExecutor.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.jetbrains.annotations.NotNull;
3030
import org.jetbrains.annotations.Nullable;
3131

32+
import java.lang.reflect.InvocationTargetException;
3233
import java.util.*;
3334
import java.util.stream.Collectors;
3435

@@ -672,28 +673,36 @@ private void invoke0(@NotNull BladeCommand cmd,
672673
cmd.instance(),
673674
args
674675
);
676+
} catch (InvocationTargetException e) {
677+
throw invocationFailure(cmd, args, e.getTargetException());
675678
} catch (Throwable t) {
676-
if (t instanceof BladeFatalError ||
677-
t instanceof BladeImplementationError ||
678-
t instanceof BladeInternalError ||
679-
t instanceof BladeInvocationError ||
680-
t instanceof BladeParseError ||
681-
t instanceof BladeUsageMessage) {
682-
// Rethrow internal errors as-is
683-
throw (RuntimeException) t;
684-
}
685-
686-
throw new BladeInvocationError(
687-
String.format(
688-
"Command invocation failed (method: %s.%s, args: %s)",
689-
cmd.method().getDeclaringClass().getName(),
690-
cmd.method().getName(),
691-
Arrays.toString(args)
692-
),
693-
t);
679+
throw invocationFailure(cmd, args, t);
694680
}
695681
}
696682

683+
@NotNull
684+
private RuntimeException invocationFailure(@NotNull BladeCommand cmd,
685+
@NotNull Object[] args,
686+
@NotNull Throwable cause) {
687+
if (cause instanceof BladeFatalError ||
688+
cause instanceof BladeImplementationError ||
689+
cause instanceof BladeInternalError ||
690+
cause instanceof BladeInvocationError ||
691+
cause instanceof BladeParseError ||
692+
cause instanceof BladeUsageMessage) {
693+
return (RuntimeException) cause;
694+
}
695+
696+
return new BladeInvocationError(
697+
String.format(
698+
"Command invocation failed (method: %s.%s, args: %s)",
699+
cmd.method().getDeclaringClass().getName(),
700+
cmd.method().getName(),
701+
Arrays.toString(args)
702+
),
703+
cause);
704+
}
705+
697706
@ApiStatus.Internal
698707
@NotNull
699708
public Object adaptSender(@NotNull BladeCommand cmd,

0 commit comments

Comments
 (0)