bazelbuild/bazel · error · OptionsParsingException
Expected value after %s
Error message
Expected value after %s
What it means
A non-boolean, non-Void option was given in the '--flag value' two-token form but no further argument exists to consume as its value. Boolean-syntax options self-default and Void options take no value, so only value-taking options reach the nextArgs.hasNext() check; at end-of-argv the value is missing and this error names the flag token.
Source
Thrown at src/main/java/com/google/devtools/common/options/OptionsParserImpl.java:836
suggestion = SpellChecker.didYouMean(arg, getAllValidArgs());
} else {
suggestion = "";
}
throw new OptionsParsingException("Unrecognized option: " + arg + suggestion, arg);
}
if (unconvertedValue == null) {
// Special-case boolean to supply value based on presence of "no" prefix.
if (lookupResult.definition.usesBooleanValueSyntax()) {
unconvertedValue = booleanValue ? "1" : "0";
} else if (lookupResult.definition.getType().equals(Void.class)) {
// This is expected, Void type options have no args.
} else if (nextArgs.hasNext()) {
// "--flag value" form
unconvertedValue = nextArgs.next();
commandLineForm.append(" ").append(unconvertedValue);
} else {
throw new OptionsParsingException("Expected value after " + arg);
}
}
if (lookupResult.fromFallback) {
// The option was not found on the current command, but is a valid option for some other
// command. Ignore it.
return new ParsedOptionDescriptionOrIgnoredArgs(
Optional.empty(), Optional.of(commandLineForm.toString()));
}
return new ParsedOptionDescriptionOrIgnoredArgs(
Optional.of(
ParsedOptionDescription.newParsedOptionDescription(
lookupResult.definition,
commandLineForm.toString(),
unconvertedValue,
new OptionInstanceOrigin(
priority,View on GitHub (pinned to e6e199d060)
Solutions
- Supply the value, ideally in '=' form to keep the pair atomic: `--platforms=//tools:platform`
- Fix the generator: when appending a value flag, append name and value together or use the '=' form in one token
- Check params files / .bazelrc for a final line that is a bare value-taking flag
Example fix
# before bazel build --platforms //... # after bazel build --platforms=//tools:default_platform //...
Defensive patterns
Strategy: validation
Validate before calling
# Ensure value flags always carry '=' so a missing value is impossible
emit() { case "$1" in --*=*) ;; --*) echo "flag '$1' needs =value" >&2; exit 2;; esac; printf '%s ' "$1"; } Prevention
- Prefer '--flag=value' over the two-token '--flag value' form
- Append flag+value pairs atomically in scripts
- Validate that params files don't end with a bare value-taking flag
When it happens
Trigger: Ending the command line with a value-taking flag: `bazel build //... --platforms`, or a params file whose last line is a bare flag; truncating an argv array mid pair.
Common situations: Scripts appending flags conditionally where the value append is skipped; params files edited by hand leaving the last flag valueless; shell line continuation breaking after the flag token.
Related errors
- A params file must be the only argument: %s
- Error reading params file: %s %s
- Malformed value of --invocation_policy:
- Tried to expand option too many times
- Unrecognized arguments:
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/8399179739e7b8a7.
Report an issue: GitHub.