Skip to content

Commit 91e8e1b

Browse files
improved error messages
1 parent e97675c commit 91e8e1b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/com/datasiqn/commandcore/command/builder/BuilderCommand.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,17 @@ public BuilderCommand(@NotNull CommandBuilder commandBuilder, List<String> usage
6565
Result<CommandNode<?>, List<String>> resultNode = current.node;
6666
if (resultNode.isError()) {
6767
if (current.extraInput) {
68-
return Result.error(Collections.singletonList("Expected end of input, but got extra args instead"));
68+
return Result.error(Collections.singletonList("Expected end of input, but got extra parameters instead"));
6969
}
7070
List<String> exceptions = resultNode.unwrapError();
71-
List<String> messages = new ArrayList<>();
72-
List<String> matches = current.args;
73-
messages.add("Invalid parameter '" + matches.get(matches.size() - 1) + "' at position " + matches.size() + ": ");
74-
messages.addAll(exceptions);
75-
return Result.error(messages);
71+
if (exceptions.isEmpty()) exceptions.add("Incorrect argument '" + reader.splice(reader.index()) + "'");
72+
String rootCommand = CommandCore.getInstance().getOptions().getRootCommand();
73+
String label = context.getLabel();
74+
String correctSection = ChatColor.GRAY + rootCommand + " " + label + " " + reader.splice(0, reader.index());
75+
String incorrectParameter = ChatColor.RED.toString() + ChatColor.UNDERLINE + reader.splice(reader.index());
76+
exceptions.add(correctSection + incorrectParameter + ChatColor.RESET + ChatColor.RED + ChatColor.ITALIC + " <--[HERE]");
77+
exceptions.add("");
78+
return Result.error(exceptions);
7679
}
7780
CommandNode<?> node = resultNode.unwrap();
7881
CommandContext newContext = buildContext(context, current);

0 commit comments

Comments
 (0)