From 08ad5f4451055abccc05fd479d674a754a0da2e8 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 30 Jun 2014 22:51:21 -0700 Subject: [PATCH] Handle exceptions thrown from bindings as a convertible InvocationTargetException. For example, if IncompleteRegionException is thrown by a binding, it will result in a InvocationTargetException now with a getCause(), which gets handled as if that exception was thrown from the actual Method that is invoked for the command. --- .../com/sk89q/worldedit/util/command/parametric/Binding.java | 5 +++-- .../worldedit/util/command/parametric/BindingHelper.java | 4 ++-- .../util/command/parametric/ParametricCallable.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/util/command/parametric/Binding.java b/src/main/java/com/sk89q/worldedit/util/command/parametric/Binding.java index dcf931c81..108fc1bf8 100644 --- a/src/main/java/com/sk89q/worldedit/util/command/parametric/Binding.java +++ b/src/main/java/com/sk89q/worldedit/util/command/parametric/Binding.java @@ -23,6 +23,7 @@ import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.util.command.binding.PrimitiveBindings; import com.sk89q.worldedit.util.command.binding.StandardBindings; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Type; import java.util.List; @@ -77,8 +78,8 @@ public interface Binding { * @throws ParameterException thrown if the parameter could not be formulated * @throws CommandException on a command exception */ - Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume) - throws ParameterException, CommandException; + Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume) + throws ParameterException, CommandException, InvocationTargetException; /** * Get a list of suggestions for the given parameter and user arguments. diff --git a/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java b/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java index b442da6a2..b56c76426 100644 --- a/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java +++ b/src/main/java/com/sk89q/worldedit/util/command/parametric/BindingHelper.java @@ -143,7 +143,7 @@ public class BindingHelper implements Binding { @Override public Object bind(ParameterData parameter, ArgumentStack scoped, - boolean onlyConsume) throws ParameterException, CommandException { + boolean onlyConsume) throws ParameterException, CommandException, InvocationTargetException { BoundMethod binding = match(parameter); List args = new ArrayList(); args.add(scoped); @@ -178,7 +178,7 @@ public class BindingHelper implements Binding { } else if (e.getCause() instanceof CommandException) { throw (CommandException) e.getCause(); } - throw new RuntimeException(e.getCause()); + throw e; } } diff --git a/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index b98aeb00f..7a657d848 100644 --- a/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -366,8 +366,8 @@ class ParametricCallable implements CommandCallable { * @throws ParameterException on an error * @throws CommandException on an error */ - private Object getDefaultValue(int i, ContextArgumentStack scoped) - throws ParameterException, CommandException { + private Object getDefaultValue(int i, ContextArgumentStack scoped) + throws ParameterException, CommandException, InvocationTargetException { CommandContext context = scoped.getContext(); ParameterData parameter = parameters[i];