{"record":{"id":"d3cba939e0563bac","repo":"bazelbuild/bazel","slug":"setvalue-operation-from-invocation-policy-sets-mul","errorCode":null,"errorMessage":"SetValue operation from invocation policy sets multiple values for %s which does not allow multiple values","messagePattern":"SetValue operation from invocation policy sets multiple values for (.+?) which does not allow multiple values","errorType":"exception","errorClass":"OptionsParsingException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java","lineNumber":565,"sourceCode":"      Level loglevel,\n      Object conversionContext,\n      ImmutableList.Builder<OptionAndRawValue> invocationPolicyFlagListBuilder)\n      throws OptionsParsingException {\n    SetValue setValue = flagPolicy.policy.getSetValue();\n    OptionDefinition optionDefinition = flagPolicy.description.getOptionDefinition();\n\n    // SetValue.flag_value must have at least 1 value.\n    if (setValue.getFlagValueCount() == 0) {\n      throw new OptionsParsingException(\n          String.format(\n              \"SetValue operation from invocation policy for %s does not have a value\",\n              optionDefinition));\n    }\n\n    // Flag must allow multiple values if multiple values are specified by the policy.\n    if (setValue.getFlagValueCount() > 1\n        && !flagPolicy.description.getOptionDefinition().allowsMultiple()) {\n      throw new OptionsParsingException(\n          String.format(\n              \"SetValue operation from invocation policy sets multiple values for %s which \"\n                  + \"does not allow multiple values\",\n              optionDefinition));\n    }\n\n    switch (setValue.getBehavior()) {\n      case UNDEFINED:\n        throw throwUndefinedBehaviorException(flagPolicy.policy);\n      case ALLOW_OVERRIDES:\n        if (valueDescription != null) {\n          // The user set the value for the flag but the flag policy is overridable, so keep the\n          // user's value.\n          logger.at(loglevel).log(\n              \"Keeping value '%s' from source '%s' for %s because the invocation policy specifying \"\n                  + \"the value(s) '%s' is overridable\",\n              valueDescription.getValue(),\n              valueDescription.getSourceString(),","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java#L547-L583","documentation":"Thrown by applySetValueOperation when a policy's set_value supplies more than one flag_value but the target option does not allow multiple values (not a repeatable/multiple-use flag). Single-valued options cannot accept a list, so the policy is rejected before enforcement.","triggerScenarios":"Policy like {\"flagName\":\"compilation_mode\",\"setValue\":{\"flagValue\":[\"opt\",\"dbg\"],...}} — compilation_mode takes exactly one value. Repeatable flags (allowsMultiple(), e.g. --define-style list flags) are the only ones that may receive multiple values.","commonSituations":"Policy authors giving multiple 'fallback' values to a single-value flag, copy-pasting a repeatable-flag policy pattern onto a scalar flag, misunderstanding that flagValue is a list only for repeated flags.","solutions":["Reduce flagValue to exactly one entry for single-valued flags.","If multiple values are genuinely needed, target a repeatable flag (one whose help shows it may be used multiple times).","Check the option definition: bazel help lists whether a flag is repeatable (shows 'multiple uses' semantics)."],"exampleFix":"// before\n{\"flagName\":\"compilation_mode\",\"setValue\":{\"flagValue\":[\"opt\",\"dbg\"],\"behavior\":\"ALLOW_OVERRIDES\"}}\n\n// after\n{\"flagName\":\"compilation_mode\",\"setValue\":{\"flagValue\":[\"opt\"],\"behavior\":\"ALLOW_OVERRIDES\"}}","handlingStrategy":"validation","validationCode":"// Multiple values only for repeatable flags\nfor (FlagPolicy fp : policy.getFlagPoliciesList()) {\n  if (fp.hasSetValue() && fp.getSetValue().getFlagValueCount() > 1) {\n    OptionDefinition def = optionIndex.get(fp.getFlagName());\n    if (def != null && !def.allowsMultiple()) {\n      throw new IllegalStateException(fp.getFlagName() + \" is single-valued; supply one flag_value\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"Catch OptionsParsingException; the message names the single-valued option — trim flagValue to one entry.","preventionTips":["Check flag repeatability in bazel help before writing multi-value policies","Only list flags (used multiple times) may take multiple flag_value entries","Keep a curated list of which org flags are repeatable"],"tags":["invocation-policy","set-value","repeatable-flags","bazel"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}