Skip to content

Commit

Permalink
explain execution coordinators & exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Nov 29, 2023
1 parent bac12a8 commit 92769be
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions docs/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ You may provide your own suggestions using a suggestion provider.

## Command Manager

### Creating a command manager
### Execution coordinators

#### Execution coordinators
The execution coordinator is responsible for coordinating command parsing and execution.
Cloud ships with two different command execution coordinators:

- **SimpleCommandExecutionCoordinator**: Performs all actions on the calling thread.
- **AsynchronousCommandExecutionCoordinator**: Uses an executor to dispatch the parsing and execution tasks.
You can change the default executor, and also force command parsing to take place on the calling thread.

### Building a command

Expand All @@ -94,8 +99,6 @@ You may provide your own suggestions using a suggestion provider.

##### Optional

### Executing a command

### Customizing the command manager

#### Pre-processing
Expand All @@ -104,6 +107,49 @@ You may provide your own suggestions using a suggestion provider.

#### Exception handling

In general, it is up to each platform manager to handle command exceptions.
Command exceptions are thrown whenever a command cannot be parsed, or executed normally.
This can be for several reasons, such as:

- The command sender does not have the required permission (NoPermissionException)
- The command sender is of the wrong type (InvalidCommandSenderException)
- The requested command does not exist (NoSuchCommandException)
- The provided command input is invalid (InvalidSyntaxException)
- The parser cannot parse the input provided (ArgumentParseException)

The command managers are highly encouraged to make use of `CommandManager#handleException`, in which case the
exception handling may be overridden using `CommandManager#registerExceptionHandler`.

##### Parser Errors

`ArgumentParseException` makes use of Cloud's caption system.
(Nearly) all argument parsers in Cloud will throw `ParserException` on invalid input, in which case you're able
to override the exception message by configuring the manager's [CaptionRegistry](TODO).
By default, Cloud uses a [FactoryDelegatingCaptionRegistry](TODO), which allows you to override the exception handling
per caption key.
All standard caption keys can be found in [StandardCaptionKey](TODO).
Some platform adapters have their own caption key classes as well.

The JavaDoc for the caption keys list their replacement variables.
The message registered for the caption will have those variables replaced with variables specific to the parser.
`{input}` is accepted by all parser captions, and will be replaced with the input that caused the exception
to be thrown.

<!-- prettier-ignore -->
!!! example
Example caption registry usage
```java
final CaptionRegistry<SenderType> registry = manager.captionRegistry();
if (registry instanceof FactoryDelegatingCaptionRegistry) {
final FactoryDelegatingCaptionRegistry<SenderType> factoryRegistry = (FactoryDelegatingCaptionRegistry<SenderType>)
manager.captionRegistry();
factoryRegistry.registerMessageFactroy(
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_BOOLEAN,
(context, key) -> "'{input}' ain't a boolean >:("
);
}
```

## Parsers

### Parser Registry
Expand Down

0 comments on commit 92769be

Please sign in to comment.