{"record":{"id":"dbe1d3e075b8e577","repo":"bazelbuild/bazel","slug":"illegal-duration-input","errorCode":null,"errorMessage":"Illegal duration '\" + input + \"'.","messagePattern":"Illegal duration '\" \\+ input \\+ \"'\\.","errorType":"validation","errorClass":"OptionsParsingException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/Converters.java","lineNumber":215,"sourceCode":"    @Override\n    public String getTypeDescription() {\n      return \"\";\n    }\n  }\n\n  /** Standard converter for the {@link java.time.Duration} type. */\n  public static class DurationConverter extends Converter.Contextless<Duration> {\n    private static final Pattern DURATION_REGEX = Pattern.compile(\"^([0-9]+)(d|h|m|s|ms|ns)$\");\n\n    @Override\n    public Duration convert(String input) throws OptionsParsingException {\n      // To be compatible with the previous parser, '0' doesn't need a unit.\n      if (\"0\".equals(input)) {\n        return Duration.ZERO;\n      }\n      Matcher m = DURATION_REGEX.matcher(input);\n      if (!m.matches()) {\n        throw new OptionsParsingException(\"Illegal duration '\" + input + \"'.\");\n      }\n      long duration = Long.parseLong(m.group(1));\n      String unit = m.group(2);\n      switch (unit) {\n        case \"d\":\n          return Duration.ofDays(duration);\n        case \"h\":\n          return Duration.ofHours(duration);\n        case \"m\":\n          return Duration.ofMinutes(duration);\n        case \"s\":\n          return Duration.ofSeconds(duration);\n        case \"ms\":\n          return Duration.ofMillis(duration);\n        case \"ns\":\n          return Duration.ofNanos(duration);\n        default:\n          throw new IllegalStateException(","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/Converters.java#L197-L233","documentation":"Thrown by Converters.DurationConverter.convert when the input does not match the regex ^([0-9]+)(d|h|m|s|ms|ns)$ and is not the special bare value \"0\". Bazel durations are integer amounts with a single lowercase unit; fractional values and missing/unknown units are rejected with an OptionsParsingException.","triggerScenarios":"Passing --timeout=100 (no unit), --timeout=1.5s (fraction), --timeout=1D or --timeout=1H (uppercase), --timeout=1hr, --timeout=1us (unsupported unit) to any Duration-typed option using this converter.","commonSituations":"Coming from tools that accept bare seconds or ISO-8601 durations (\"PT2H\", \"2h30m\"); compounding units like \"1m30s\" which the single-unit regex rejects; uppercase or abbreviated units (us instead of ns).","solutions":["Write an integer count plus one lowercase unit: e.g. 90s, 5m, 2h, 1d, 500ms, 100ns.","Normalize compound durations yourself: 1m30s -> 90s.","Zero can be written bare as 0."],"exampleFix":"# before\nbazel test --test_timeout=1m30s //...\n# after\nbazel test --test_timeout=90s //...","handlingStrategy":"validation","validationCode":"private static final Pattern OK = Pattern.compile(\"^([0-9]+)(d|h|m|s|ms|ns)$\");\n\nboolean isParsableDuration(String s) {\n  return \"0\".equals(s) || (s != null && OK.matcher(s).matches());\n}","typeGuard":"boolean isDurationFlagValue(String s) {\n  return s != null && (s.equals(\"0\") || s.matches(\"[0-9]+(d|h|m|s|ms|ns)\"));\n}","tryCatchPattern":null,"preventionTips":["Always attach a lowercase unit; bare numbers other than 0 are rejected.","Compound durations (1m30s) are invalid: pre-compute a single unit value.","Use ns not us for sub-millisecond values."],"tags":["bazel","options","converter","duration","cli"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}