bazelbuild/bazel · error · OptionsParsingException

Unexpected value after boolean option: %s

Error message

Unexpected value after boolean option: %s

What it means

When '--no<optionName>' resolves to a boolean-syntax option, the 'no' prefix itself already supplies the value false, so attaching '=value' is contradictory and rejected. Only the affirmative spelling '--<optionName>=value' may carry an explicit value for boolean-syntax options.

Source

Thrown at src/main/java/com/google/devtools/common/options/OptionsParserImpl.java:799

      if (name.trim().isEmpty()) {
        throw new OptionsParsingException("Invalid options syntax: " + arg, arg);
      }
      unconvertedValue = equalsAt == -1 ? null : arg.substring(equalsAt + 1);
      lookupResult = getWithFallback(OptionsData::getOptionDefinitionFromName, name, fallbackData);

      // Look for a "no"-prefixed option name: "no<optionName>".
      if (lookupResult == null && name.startsWith("no")) {
        name = name.substring(2);
        lookupResult =
            getWithFallback(OptionsData::getOptionDefinitionFromName, name, fallbackData);
        booleanValue = false;
        if (lookupResult != null) {
          if (!lookupResult.definition.usesBooleanValueSyntax()) {
            throw new OptionsParsingException(
                "Illegal use of 'no' prefix on non-boolean option: " + arg, arg);
          }
          if (unconvertedValue != null) {
            throw new OptionsParsingException("Unexpected value after boolean option: " + arg, arg);
          }
          // "no<optionname>" signifies a boolean option w/ false value
          unconvertedValue = "0";
        }
      }
      parsedOptionName = name;
    } else {
      throw new OptionsParsingException("Invalid options syntax: " + arg, arg);
    }

    // Do not recognize internal options, which are treated as if they did not exist.
    if (lookupResult == null || shouldIgnoreOption(lookupResult.definition)) {
      if (isFirstRoundOfParsing) {
        return new ParsedOptionDescriptionOrIgnoredArgs(Optional.empty(), Optional.of(arg));
      }
      String suggestion;
      // Do not offer suggestions for short-form options.
      if (arg.startsWith("--")) {

View on GitHub (pinned to e6e199d060)

Solutions

  1. Drop the value: write `--nobuild_tests_only` alone
  2. Or use the positive spelling with a value: `--build_tests_only=false`
  3. Sweep .bazelrc, CI yaml, and wrapper scripts for '--no...=' patterns

Example fix

# before
bazel test --nobuild_tests_only=true //...
# after
bazel test --nobuild_tests_only //...   # or --build_tests_only=false
Defensive patterns

Strategy: validation

Validate before calling

# Normalize flags: forbid '--no...=' combinations
for arg in "$@"; do
  case "$arg" in
    --no*=*) echo "Boolean --no flags cannot take a value: $arg" >&2; exit 2;;
  esac
done

Prevention

When it happens

Trigger: Passing a token like `--nobuild_tests_only=true`, `--nokeep_going=0`, or any --no-prefixed boolean flag with an '=' clause.

Common situations: Configuring rc files (.bazelrc) or CI matrices that uniformly append '=true'/'=false' to every flag; converting a value flag to boolean and leaving '=value' in existing configs.

Related errors


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/5c8943f2ba5071d4. Report an issue: GitHub.