Don't print invalid type error to stderr
This commit is contained in:
parent
f02c33d95a
commit
82d520d808
@ -22,4 +22,8 @@ public abstract class CommandErrorMessageException extends CommandException {
|
|||||||
protected CommandErrorMessageException(String reason) {
|
protected CommandErrorMessageException(String reason) {
|
||||||
super(reason);
|
super(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CommandErrorMessageException(String reason, Throwable cause) {
|
||||||
|
super(reason, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,8 @@ public abstract class CommandException extends Exception implements ICommandExce
|
|||||||
protected CommandException(String reason) {
|
protected CommandException(String reason) {
|
||||||
super(reason);
|
super(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CommandException(String reason, Throwable cause) {
|
||||||
|
super(reason, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,21 @@ public abstract class CommandInvalidArgumentException extends CommandErrorMessag
|
|||||||
|
|
||||||
public final ICommandArgument arg;
|
public final ICommandArgument arg;
|
||||||
|
|
||||||
protected CommandInvalidArgumentException(ICommandArgument arg, String reason) {
|
protected CommandInvalidArgumentException(ICommandArgument arg, String message) {
|
||||||
super(String.format(
|
super(formatMessage(arg, message));
|
||||||
"Error at argument #%s: %s",
|
|
||||||
arg.getIndex() == -1 ? "<unknown>" : Integer.toString(arg.getIndex() + 1),
|
|
||||||
reason
|
|
||||||
));
|
|
||||||
this.arg = arg;
|
this.arg = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CommandInvalidArgumentException(ICommandArgument arg, String message, Throwable cause) {
|
||||||
|
super(formatMessage(arg, message), cause);
|
||||||
|
this.arg = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatMessage(ICommandArgument arg, String message) {
|
||||||
|
return String.format(
|
||||||
|
"Error at argument #%s: %s",
|
||||||
|
arg.getIndex() == -1 ? "<unknown>" : Integer.toString(arg.getIndex() + 1),
|
||||||
|
message
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) {
|
public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) {
|
||||||
super(arg, String.format("Expected %s.\nMore details: %s", expected, cause.getMessage()));
|
super(arg, String.format("Expected %s", expected), cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) {
|
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) {
|
||||||
@ -34,6 +34,6 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) {
|
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) {
|
||||||
super(arg, String.format("Expected %s, but got %s instead.\nMore details: %s", expected, got, cause.getMessage()));
|
super(arg, String.format("Expected %s, but got %s instead", expected, got), cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,8 +316,7 @@ public class ArgConsumer implements IArgConsumer {
|
|||||||
try {
|
try {
|
||||||
return datatype.apply(this.context, original);
|
return datatype.apply(this.context, original);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
|
||||||
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +345,7 @@ public class ArgConsumer implements IArgConsumer {
|
|||||||
try {
|
try {
|
||||||
return datatype.get(this.context);
|
return datatype.get(this.context);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
|
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user