Skip to content
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

Fix format specifiers when adding invalid choices #2628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ public AutoCompleteCallbackAction addChoices(@Nonnull Collection<Command.Choice>
"Choice of type %s cannot be converted to INTEGER", choice.getType());
long valueLong = choice.getAsLong();
Checks.check(valueLong <= OptionData.MAX_POSITIVE_NUMBER,
"Choice value cannot be larger than %d Provided: %d",
"Choice value cannot be larger than %f Provided: %d",
OptionData.MAX_POSITIVE_NUMBER, valueLong);
Checks.check(valueLong >= OptionData.MIN_NEGATIVE_NUMBER,
"Choice value cannot be smaller than %d. Provided: %d",
"Choice value cannot be smaller than %f. Provided: %d",
OptionData.MIN_NEGATIVE_NUMBER, valueLong);
break;
case NUMBER:
Checks.check(choice.getType() == OptionType.NUMBER || choice.getType() == OptionType.INTEGER,
"Choice of type %s cannot be converted to NUMBER", choice.getType());
double valueDouble = choice.getAsDouble();
Checks.check(valueDouble <= OptionData.MAX_POSITIVE_NUMBER,
"Choice value cannot be larger than %d Provided: %d",
"Choice value cannot be larger than %f Provided: %f",
OptionData.MAX_POSITIVE_NUMBER, valueDouble);
Checks.check(valueDouble >= OptionData.MIN_NEGATIVE_NUMBER,
"Choice value cannot be smaller than %d. Provided: %d",
"Choice value cannot be smaller than %f. Provided: %f",
OptionData.MIN_NEGATIVE_NUMBER, valueDouble);
break;
case STRING:
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/dv8tion/jda/internal/utils/Checks.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.dv8tion.jda.api.interactions.components.ActionComponent;
import net.dv8tion.jda.api.interactions.components.Component;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import org.intellij.lang.annotations.PrintFormat;
import org.jetbrains.annotations.Contract;

import java.util.*;
Expand Down Expand Up @@ -63,14 +64,14 @@ public static void check(final boolean expression, final String message)
}

@Contract("false, _, _ -> fail")
public static void check(final boolean expression, final String message, final Object... args)
public static void check(final boolean expression, @PrintFormat final String message, final Object... args)
{
if (!expression)
throw new IllegalArgumentException(String.format(message, args));
}

@Contract("false, _, _ -> fail")
public static void check(final boolean expression, final String message, final Object arg)
public static void check(final boolean expression, @PrintFormat final String message, final Object arg)
{
if (!expression)
throw new IllegalArgumentException(String.format(message, arg));
Expand Down
Loading