|
29 | 29 | import org.jetbrains.annotations.NotNull; |
30 | 30 | import org.jetbrains.annotations.Nullable; |
31 | 31 |
|
| 32 | +import java.lang.reflect.InvocationTargetException; |
32 | 33 | import java.util.*; |
33 | 34 | import java.util.stream.Collectors; |
34 | 35 |
|
@@ -672,28 +673,36 @@ private void invoke0(@NotNull BladeCommand cmd, |
672 | 673 | cmd.instance(), |
673 | 674 | args |
674 | 675 | ); |
| 676 | + } catch (InvocationTargetException e) { |
| 677 | + throw invocationFailure(cmd, args, e.getTargetException()); |
675 | 678 | } 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); |
694 | 680 | } |
695 | 681 | } |
696 | 682 |
|
| 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 | + |
697 | 706 | @ApiStatus.Internal |
698 | 707 | @NotNull |
699 | 708 | public Object adaptSender(@NotNull BladeCommand cmd, |
|
0 commit comments