Improve error messaging for missing placeholder.
GITHUB_BREAKING_CHANGES=The "No value provided for" error messages for an invalid placeholder name now include the expected placeholder values. And another spot where an invalid placeholder name resulted in an NPE now throws an `IllegalStateException` with a similar error message.
@@ -484,6 +484,13 @@ public final class JbcSrcRuntime {
}
}
SoyValueProvider placeholderValue = (SoyValueProvider) placeholders.get(placeholderName);
+ if (placeholderValue == null) {
+ throw new IllegalStateException(
+ "No value provided for placeholder: '"
+ + placeholderValue
+ + "', expected one of "
+ + placeholders.keySet());
+ }
try {
RenderResult result = placeholderValue.renderAndResolve(out, /* isLast= */ false);
if (!result.isDone()) {
@@ -578,7 +585,11 @@ public final class JbcSrcRuntime {
private String getSelectCase(String selectVarName) {
String selectCase = (String) placeholders.get(selectVarName);
if (selectCase == null) {
- throw new IllegalArgumentException("No value provided for select: '" + selectVarName + "'");
+ throw new IllegalArgumentException(
+ "No value provided for select: '"
+ + selectVarName
+ + "', expected one of "
+ + placeholders.keySet());
}
return selectCase;
}
@@ -587,7 +598,11 @@ public final class JbcSrcRuntime {
private double getPlural(String pluralVarName) {
NumberData pluralValue = (NumberData) placeholders.get(pluralVarName);
if (pluralValue == null) {
- throw new IllegalArgumentException("No value provided for plural: '" + pluralVarName + "'");
+ throw new IllegalArgumentException(
+ "No value provided for plural: '"
+ + pluralVarName
+ + "', expected one of "
+ + placeholders.keySet());
}
return pluralValue.numberValue();
}
