-
-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API-8] Error "types" for CommandResults #2385
Comments
Before I delve into this issue proper, I want to explain a little bit about how commands are dispatched at runtime in Sponge. Note that I'm simply going to talk about this in the context of parameterised commands, but most registrars will do things the same way. There are effectively five steps to command execution, so for a command
Point 1 is easy for us to control (in the Sponge domain), and point 4 is not too contraversial because that'll normally be handled as part of However, point 3 is a problem - parsing. Because of the way our parsers work, there may be a multitude of reasons why a single command invocation failed. Take, for example, this command tree:
If a player runs the command above, the parser will try all available routes before failing. The reasons for failure are:
What do we report due to this parse time failure? The reasons for failure are varied and multiple, and all of them are valid errors. I'm loathed to make the API more complicated to add such error reasons in. For execution time, that's fine, we'd just Your specific comment on using a WorldEdit command is interesting, simply because that's a good example of where this might fall down further. It's quite possible that, as a cross platform system, they assume the official Sponge impl and use the Brigadier registrar to register their commands. This is a vanilla like registrar and we basically don't touch it other than to register alises to the command manager. We won't have a clue why a command fails, we only know the result of an invocation request - that is, if it worked or not. I understand the use case of customising the error message when the command is not in the manager. That would be easy. Beyond that, the manager does not have control and any reason would be at the mercy of the registrar or plugin - and even for our internal registrars, particularly the Vanilla one, this would be a challenge. I'm not even comfortable just providing the step where it failed (which would be something like SELECT, PARSE, EXECUTE) because beyond select, the steps are going to be registrar dependent. Finally, in our implementation, we throw any exceptions that occurred back further to Minecraft, beyond our command manager, to let Minecraft handle the command exceptions, which it does by reading the message in the exception. Customising this would be expensive as we would need to create another exception for the message. Truth be told this is a minor issue as I could just stop the exception bubbling (I don't think we show the error anyway) but that then indicates a success to Minecraft and we might not want to do that. Basically, this is a complicated problem, far more complicated than you're proposing, and I think it's likely to be inconsistent at best, particularly around parse time errors. |
Wow. Yeah, I was not expecting this but greatly appreciate the full explanation! |
Right now,
CommandResult
s can either be successful or have aComponent
error message, but if another plugin would like to understand why a command resulted in an error, theComponent
would have to be parsed by the interested plugin.This parsing by hand is fine for the Sponge-specific error messages that take on a consistent format, but if other plugins deviate and write their own error messages, a plugin attempting to capture those errors would have a hard time doing so in a consistent way.
My proposal are having different error "types" that can be attached to a
CommandResult.error()
that fall under common error categories. These categories are things like "not having permission" or "command couldn't be parsed," along with a more general "catch all" category for errors that can't otherwise be categorized. There likely wouldn't be too many of these categories.As an example use-case, let's take a plugin like WorldEdit which has navigation commands. Using
/ascend
as an example command, I might want to change the error message that the command gives off if a player does not have permission to be something like "If you'd like to use/ascend
, you need to have the Squid rank!" without changing other error messages by mistake. Those messages would of course need to be modified by another plugin, but that second plugin wouldn't need to know anything about the error message it is modifying other than its "type."There may be better ways to do this, so I'd love to hear other thoughts, thanks!
The text was updated successfully, but these errors were encountered: