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

Use debugPrint instead of str for fail arguments #18818

Closed
wants to merge 5 commits into from
Closed
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
32 changes: 19 additions & 13 deletions src/main/java/net/starlark/java/eval/MethodLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
package net.starlark.java.eval;

import com.google.common.base.Ascii;
import com.google.common.base.Joiner;
import com.google.common.collect.Ordering;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import net.starlark.java.annot.Param;
import net.starlark.java.annot.ParamType;
Expand Down Expand Up @@ -706,24 +703,33 @@ public StarlarkList<?> dir(Object object, StarlarkThread thread) throws EvalExce
@Param(
name = "args",
doc =
"A list of values, formatted with str and joined with spaces, that appear in the"
+ " error message."),
"A list of values, formatted with debugPrint (which is equivalent to str by"
+ " default) and joined with spaces, that appear in the error message."),
useStarlarkThread = true)
public void fail(Object msg, Object attr, Tuple args, StarlarkThread thread)
throws EvalException {
List<String> elems = new ArrayList<>();
Printer printer = new Printer();
boolean needSeparator = false;
if (attr != Starlark.NONE) {
printer.append("attribute ").append((String) attr).append(":");
needSeparator = true;
}
// msg acts like a leading element of args.
if (msg != Starlark.NONE) {
elems.add(Starlark.str(msg, thread.getSemantics()));
if (needSeparator) {
printer.append(" ");
}
printer.debugPrint(msg, thread.getSemantics());
needSeparator = true;
}
for (Object arg : args) {
elems.add(Starlark.str(arg, thread.getSemantics()));
}
String str = Joiner.on(" ").join(elems);
if (attr != Starlark.NONE) {
str = String.format("attribute %s: %s", attr, str);
if (needSeparator) {
printer.append(" ");
}
printer.debugPrint(arg, thread.getSemantics());
needSeparator = true;
}
throw Starlark.errorf("%s", str);
throw Starlark.errorf("%s", printer.toString());
}

@StarlarkMethod(
Expand Down