bazelbuild/bazel · error · IOException
too many positional arguments
Error message
too many positional arguments
What it means
The Starlark interpreter CLI accepts at most one positional argument (the script file). After flag parsing, if more than one non-flag token remains, parsing aborts with this IOException. Note the script file's own arguments are not supported by this CLI — everything must reach the script through -c or the file itself.
Source
Thrown at src/main/java/net/starlark/java/cmd/Main.java:203
}
if (args[i].equals("-c")) {
if (i + 1 == args.length) {
throw new IOException("-c <cmd> flag needs an argument");
}
cmd = args[++i];
} else if (args[i].equals("-cpuprofile")) {
if (i + 1 == args.length) {
throw new IOException("-cpuprofile <file> flag needs an argument");
}
cpuprofile = args[++i];
} else {
throw new IOException("unknown flag: " + args[i]);
}
}
// positional arguments
if (i < args.length) {
if (i + 1 < args.length) {
throw new IOException("too many positional arguments");
}
file = args[i];
}
if (cpuprofile != null) {
FileOutputStream out = new FileOutputStream(cpuprofile);
Starlark.startCpuProfile(out, Duration.ofMillis(10));
}
int exit;
if (file == null) {
if (cmd != null) {
exit = execute(ParserInput.fromString(cmd, "<command-line>"));
} else {
readEvalPrintLoop();
exit = 0;
}
} else if (cmd == null) {View on GitHub (pinned to e6e199d060)
Solutions
- Run one script per invocation: `starlark script.star`.
- Pass data into the script via -c or embed it in the file instead of positional args.
- Quote/limit shell globbing so exactly one file matches.
- If argv forwarding is needed, use a wrapper that reads a single pre-processed script.
Example fix
# before starlark a.star b.star # after starlark a.star && starlark b.star
Defensive patterns
Strategy: validation
Validate before calling
# Count positional args before launch
files=(); for a in "$@"; do [[ "$a" != -* ]] && files+=("$a"); done
if (( ${#files[@]} > 1 )); then echo "only one script file allowed" >&2; exit 2; fi Prevention
- Invoke one script per process.
- Pass script data via -c or generate a single combined file.
- Quote globs in wrapper scripts.
When it happens
Trigger: Running `starlark a.star b.star` or `starlark script.star --flag value`; script arguments passed after the filename.
Common situations: Treating this minimal CLI like a general-purpose interpreter that forwards argv to the script; batching multiple scripts in one invocation; leftover shell-glob expansions producing multiple files.
Related errors
- -c <cmd> flag needs an argument
- -cpuprofile <file> flag needs an argument
- unknown flag: %s
- Usage: %s -- command arg1 @args
- \nUsage: %s -- command arg1 @args\n
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/14ea05b798c9ef88.
Report an issue: GitHub.