Error Handling¶
Exceptions¶
JDA-Commands defines a set of custom runtime exceptions that can occur:
ConfigurationExceptionwill be thrown if anything goes wrong while configuring JDA-CommandsInvalidDeclarationExceptionwill be thrown if any errors are made in the declaration of interactionsParsingExceptionwill be thrown if the JSON parsing of the Embed API failsInternalExceptionwill be thrown if anything goes wrong internally. These errors should be reported to the devs
If a ConfigurationException
or InvalidDeclarationException
occurs during startup, JDA-Commands will shut down itself as well as JDA. To disable this behaviour, set JDACBuilder#shutdownJDA(boolean)
to false.
Error Messages¶
As mentioned before, JDA-Commands has a set of error messages it uses all over the place. These messages include:
- Command Execution Failed Message (used for Exceptions)
- Constraint Failed Message (see Validators)
- Insufficient Permissions Message (see Permissions System)
- Timed Out Component Message (see Runtime Concept)
- Type Adapting Failed Message (see Type Adapters)
You can customize these error messages by providing an implementation of ErrorMessageFactory either at the builder or
by annotating it with Implementation.
Example
To make things easier, these error messages can also be loaded from a JSON source using the Embed API.
Therefore, you have to pass an EmbedDataSource to the EmbedConfig.
JDACommands.builder(jda, Main.class)
.embeds(config -> config.errorSource(EmbedDataSource.file(Path.of("errorEmbeds.json")))
.start();
{ $placeholders } can be placed anywhere in the embeds and will get injected by JDA-Commands.