bazelbuild/bazel · error · OptionsParsingException

Invalid size: " + input

Error message

Invalid size: " + input

What it means

Thrown by ByteSizeConverter.convert when the input does not match its PATTERN at all — i.e. it is not a number optionally followed by a K/M/G/T multiplier suffix (e.g. 'abc', '1X', '1.5G' if fractions are not in the pattern). This is the pre-parse rejection, before Long.parseLong or the multiplier math is attempted.

Source

Thrown at src/main/java/com/google/devtools/common/options/Converters.java:697

    private static final Pattern PATTERN =
        Pattern.compile("(?<value>[0-9]+)(?<multiplier>[KMGT]?)");

    private static final ImmutableMap<String, Long> MULTIPLIER_MAP =
        ImmutableMap.of(
            "K",
            1024L,
            "M",
            1024L * 1024L,
            "G",
            1024L * 1024L * 1024L,
            "T",
            1024L * 1024L * 1024L * 1024L);

    @Override
    public Long convert(String input) throws OptionsParsingException {
      Matcher m = PATTERN.matcher(input);
      if (!m.matches()) {
        throw new OptionsParsingException("Invalid size: " + input);
      }
      try {
        long value = Long.parseLong(m.group("value"));
        String mult = m.group("multiplier");
        if (!mult.isEmpty()) {
          value = Math.multiplyExact(value, (long) MULTIPLIER_MAP.get(mult));
        }
        return value;
      } catch (NumberFormatException | ArithmeticException e) {
        throw new OptionsParsingException("Invalid size: " + input, e);
      }
    }

    @Override
    public String getTypeDescription() {
      return "a size in bytes, optionally followed by a K, M, G or T multiplier";
    }
  }

View on GitHub (pinned to e6e199d060)

Solutions

  1. Use the documented form: integer optionally followed by one of K, M, G, T (e.g. 1024, 512M, 4G).
  2. Remove spaces and unsupported suffixes: '500MB' -> '500M', '10 K' -> '10K'.
  3. If the value comes from a script, validate with regex ^[0-9]+[KMGT]?$ before invoking bazel.

Example fix

# before
--experimental_disk_cache_size=500MB

# after
--experimental_disk_cache_size=500M
Defensive patterns

Strategy: validation

Validate before calling

// Mirror the parser's accepted grammar before invoking bazel
boolean isValidSize(String s) {
  return s != null && s.matches("[0-9]+[KMGT]?");
}

Try / catch

Catch OptionsParsingException around flag parsing; e.getMessage() includes the invalid input verbatim, so fail fast with that context rather than retrying.

Prevention

When it happens

Trigger: Passing a non-numeric or wrongly-suffixed value to any byte-size flag (e.g. --memory_limit, JVM heap-style flags using this converter): 'unlimited', '1B' (B suffix unsupported per the type description), '10 K' with a space, '1.5G'.

Common situations: Assuming 'B' or lowercase 'k'/'m' suffixes work, leaving shell-expanded spaces inside the value, passing a unit like '500MB' instead of '500M', flags scripted from variables that come out empty or as 'null'.

Related errors


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