{"record":{"id":"0d067721a19a064c","repo":"bazelbuild/bazel","slug":"not-a-valid-s-s-should-be-s","errorCode":null,"errorMessage":"Not a valid %s: '%s' (should be %s)","messagePattern":"Not a valid (.+?): '(.+?)' \\(should be (.+?)\\)","errorType":"validation","errorClass":"OptionsParsingException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/EnumConverter.java","lineNumber":79,"sourceCode":"            String.format(\n                \"Enum type %s values %s and %s collide in their case-insensitive string\"\n                    + \" representation '%s'\",\n                enumType.getName(), enumConstants.get(key).name(), value.name(), key));\n      }\n      enumConstants.put(key, value);\n    }\n    return enumType;\n  }\n\n  /** Implements {@link Converter#convert(String, Object)}. */\n  @Override\n  public T convert(String input) throws OptionsParsingException {\n    for (T value : enumType.getEnumConstants()) {\n      if (Ascii.equalsIgnoreCase(value.toString(), input)) {\n        return value;\n      }\n    }\n    throw new OptionsParsingException(\n        \"Not a valid %s: '%s' (should be %s)\".formatted(typeName, input, getTypeDescription()));\n  }\n\n  /** Implements {@link #getTypeDescription()}. */\n  @Override\n  public String getTypeDescription() {\n    return Ascii.toLowerCase(\n        Converters.joinEnglishList(Arrays.asList(enumType.getEnumConstants())));\n  }\n\n  @Override\n  public boolean starlarkConvertible() {\n    return true;\n  }\n\n  @Override\n  public String reverseForStarlark(Object converted) {\n    checkArgument(enumType.isInstance(converted));","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/EnumConverter.java#L61-L97","documentation":"Thrown by EnumConverter.convert when the supplied string does not case-insensitively match any constant of the target enum. The message names the type, echoes the input, and lists the accepted values (the lowercase-joined enum constants) via getTypeDescription().","triggerScenarios":"Passing an unrecognized value to any enum-typed option, e.g. --compilation_mode=native (valid: fastbuild, dbg, opt), --strategy=blah, or an enum value that only exists in newer Bazel versions. Matching is Ascii.equalsIgnoreCase against value.toString().","commonSituations":"Version skew: a flag value added in a newer Bazel used against an older binary (or vice versa), typos and abbreviations, using uppercase internally-mapped names that differ from the enum constant spelling, CI pinned to an old Bazel while developers use new flags.","solutions":["Read the '(should be ...)' list in the message and use one of those exact values (case-insensitive).","Check the flag's accepted values for your Bazel version: bazel help <command> or the flag's --help output shows the type description.","For version-skew, gate the flag in scripts by Bazel version, or upgrade/downgrade Bazel to the version that supports the value.","Enable shell completion or validate enum values in wrapper scripts before invoking bazel."],"exampleFix":"# before\nbazel build --compilation_mode=fast\n\n# after\nbazel build --compilation_mode=fastbuild","handlingStrategy":"validation","validationCode":"// Validate against the actual enum before invoking bazel\nSet<String> allowed = Arrays.stream(CompilationMode.values())\n    .map(Enum::name).collect(toSet());\nif (!allowed.contains(userValue.toUpperCase(Locale.ROOT))) {\n  throw new IllegalArgumentException(\"Value must be one of \" + allowed);\n}","typeGuard":"// Java type guard over the option's enum\nstatic Optional<CompilationMode> asCompilationMode(String s) {\n  return Arrays.stream(CompilationMode.values())\n      .filter(v -> v.name().equalsIgnoreCase(s)).findFirst();\n}","tryCatchPattern":"Catch OptionsParsingException and print the '(should be ...)' list from the message to the user verbatim — it is generated from the enum itself and always matches the binary in use.","preventionTips":["Derive allowed values from the running Bazel version (bazel help output) in wrapper scripts","Gate enum flag usage on Bazel version checks in CI","Prefer scripting against stable enum values"],"tags":["options-parsing","enum","converter","version-skew","bazel"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}