starlark: eliminate one deprecated EvalException constructor
(the easy one)
PiperOrigin-RevId: 341844447
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java
index 4e112a2..fe5bd9d 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java
@@ -564,11 +564,10 @@
}
if (!Attribute.isImplicit(nativeName) && !Attribute.isLateBound(nativeName)) {
if (!attribute.checkAllowedValues() || attribute.getType() != Type.STRING) {
- throw new EvalException(
- String.format(
- "Aspect parameter attribute '%s' must have type 'string' and use the "
- + "'values' restriction.",
- nativeName));
+ throw Starlark.errorf(
+ "Aspect parameter attribute '%s' must have type 'string' and use the 'values'"
+ + " restriction.",
+ nativeName);
}
if (!hasDefault) {
requiredParams.add(nativeName);
@@ -576,16 +575,14 @@
PredicateWithMessage<Object> allowed = attribute.getAllowedValues();
Object defaultVal = attribute.getDefaultValue(null);
if (!allowed.apply(defaultVal)) {
- throw new EvalException(
- String.format(
- "Aspect parameter attribute '%s' has a bad default value: %s",
- nativeName, allowed.getErrorReason(defaultVal)));
+ throw Starlark.errorf(
+ "Aspect parameter attribute '%s' has a bad default value: %s",
+ nativeName, allowed.getErrorReason(defaultVal));
}
}
} else if (!hasDefault) { // Implicit or late bound attribute
String starlarkName = "_" + nativeName.substring(1);
- throw new EvalException(
- String.format("Aspect attribute '%s' has no default value.", starlarkName));
+ throw Starlark.errorf("Aspect attribute '%s' has no default value.", starlarkName);
}
if (attribute.getDefaultValueUnchecked() instanceof StarlarkComputedDefaultTemplate) {
// Attributes specifying dependencies using computed value are currently not supported.
@@ -595,21 +592,19 @@
// Current logic in StarlarkComputedDefault is not enough,
// however {Conservative,Precise}AspectResolver can probably be improved to make that work.
String starlarkName = "_" + nativeName.substring(1);
- throw new EvalException(
- String.format(
- "Aspect attribute '%s' (%s) with computed default value is unsupported.",
- starlarkName, attribute.getType()));
+ throw Starlark.errorf(
+ "Aspect attribute '%s' (%s) with computed default value is unsupported.",
+ starlarkName, attribute.getType());
}
attributes.add(attribute);
}
for (Object o : providesArg) {
if (!StarlarkAttrModule.isProvider(o)) {
- throw new EvalException(
- String.format(
- "Illegal argument: element in 'provides' is of unexpected type. "
- + "Should be list of providers, but got item of type %s. ",
- Starlark.type(o)));
+ throw Starlark.errorf(
+ "Illegal argument: element in 'provides' is of unexpected type. "
+ + "Should be list of providers, but got item of type %s. ",
+ Starlark.type(o));
}
}
return new StarlarkDefinedAspect(
@@ -816,7 +811,9 @@
try {
this.ruleClass = builder.build(ruleClassName, starlarkLabel + "%" + ruleClassName);
} catch (IllegalArgumentException | IllegalStateException ex) {
- throw new EvalException(definitionLocation, ex);
+ // TODO(adonovan): this catch statement is an abuse of exceptions. Be more specific.
+ String msg = ex.getMessage();
+ throw new EvalException(definitionLocation, msg != null ? msg : ex.toString(), ex);
}
this.builder = null;
diff --git a/src/main/java/net/starlark/java/eval/EvalException.java b/src/main/java/net/starlark/java/eval/EvalException.java
index 7eee58c..f25255e 100644
--- a/src/main/java/net/starlark/java/eval/EvalException.java
+++ b/src/main/java/net/starlark/java/eval/EvalException.java
@@ -66,7 +66,12 @@
/** Constructs an EvalException using the same message as the cause exception. */
public EvalException(Throwable cause) {
- this((Location) null, cause);
+ this((Location) null, getCauseMessage(cause), cause);
+ }
+
+ private static String getCauseMessage(Throwable cause) {
+ String msg = cause.getMessage();
+ return msg != null ? msg : cause.toString();
}
// TODO(adonovan): delete all constructors below. Stop using Location.
@@ -97,23 +102,6 @@
this.location = location;
}
- /**
- * Constructs an EvalException with an optional location (deprecated) using the same message as
- * the cause exception.
- *
- * <p>See notes at {@link #EvalException(Location, String)}.
- */
- // TODO(adonovan): eliminate.
- public EvalException(@Nullable Location location, Throwable cause) {
- super(getCauseMessage(cause), cause);
- this.location = location;
- }
-
- private static String getCauseMessage(Throwable cause) {
- String msg = cause.getMessage();
- return msg != null ? msg : cause.toString();
- }
-
/** Returns the error message. Does not include location (deprecated), call stack, or cause. */
@Override
public final String getMessage() {
@@ -162,7 +150,7 @@
}
/**
- * A SourceReader reads the line of source denoted by a Location to be displayed in a formatted a
+ * A SourceReader reads the line of source denoted by a Location to be displayed in a formatted
* stack trace.
*/
public interface SourceReader {