Added CommandExecutionException which wraps any exception thrown during the execution of command handlers. Should be handled using CommandManager#registerExceptionHandler, similar to NoSuchCommandException, ArgumentParseException, etc.

This commit is contained in:
jmp 2020-11-19 19:50:17 -08:00 committed by Alexander Söderberg
parent 2f0ded5be6
commit 7df6917fe4
14 changed files with 240 additions and 32 deletions

View file

@ -24,6 +24,7 @@
package cloud.commandframework.jda;
import cloud.commandframework.exceptions.ArgumentParseException;
import cloud.commandframework.exceptions.CommandExecutionException;
import cloud.commandframework.exceptions.InvalidCommandSenderException;
import cloud.commandframework.exceptions.InvalidSyntaxException;
import cloud.commandframework.exceptions.NoPermissionException;
@ -41,6 +42,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
@SuppressWarnings("deprecation")
public class JDACommandListener<C> extends ListenerAdapter {
private static final String MESSAGE_INTERNAL_ERROR = "An internal error occurred while attempting to perform this command.";
private static final String MESSAGE_INVALID_SYNTAX = "Invalid Command Syntax. Correct command syntax is: ";
private static final String MESSAGE_NO_PERMS = "I'm sorry, but you do not have permission to perform this command. "
+ "Please contact the server administrators if you believe that this is in error.";
@ -116,6 +118,16 @@ public class JDACommandListener<C> extends ListenerAdapter {
.getMessage()
)
);
} else if (throwable instanceof CommandExecutionException) {
this.commandManager.handleException(sender, CommandExecutionException.class,
(CommandExecutionException) throwable, (c, e) -> {
this.sendMessage(
event,
MESSAGE_INTERNAL_ERROR
);
throwable.getCause().printStackTrace();
}
);
} else {
this.sendMessage(event, throwable.getMessage());
}