bazelbuild/bazel · error · OptionsParsingException
SetValue operation from invocation policy for has an undefin
Error message
SetValue operation from invocation policy for has an undefined behavior: %s
What it means
Thrown by throwUndefinedBehaviorException when a policy's set_value operation has behavior = UNDEFINED (the proto default), which deliberately means 'behavior was not specified'. Because the enforcement semantics (override vs final vs append) are ambiguous, the enforcer refuses rather than guessing. The message text itself contains a grammar slip ('for has an undefined behavior').
Source
Thrown at src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java:313
return effectivePolicy.buildKeepingLast().values().asList();
}
private static void throwAllowValuesOnExpansionFlagException(String flagName)
throws OptionsParsingException {
throw new OptionsParsingException(
String.format("Allow_Values on expansion flags like %s is not allowed.", flagName));
}
private static void throwDisallowValuesOnExpansionFlagException(String flagName)
throws OptionsParsingException {
throw new OptionsParsingException(
String.format("Disallow_Values on expansion flags like %s is not allowed.", flagName));
}
private static OptionsParsingException throwUndefinedBehaviorException(FlagPolicy policy)
throws OptionsParsingException {
throw new OptionsParsingException(
String.format(
"SetValue operation from invocation policy for has an undefined behavior: %s",
policy
));
}
/**
* Expand a single policy. If the policy is not about an expansion flag, this will simply return a
* list with a single element, oneself. If the policy is for an expansion flag, the policy will
* get split into multiple policies applying to each flag the original flag expands to.
*
* <p>None of the flagPolicies returned should be on expansion flags.
*/
private static ImmutableList<FlagPolicyWithContext> expandPolicy(
FlagPolicyWithContext originalPolicy, OptionsParser parser, Level loglevel)
throws OptionsParsingException {
ImmutableList.Builder<FlagPolicyWithContext> expandedPolicies = ImmutableList.builder();
View on GitHub (pinned to e6e199d060)
Solutions
- Add an explicit behavior to the setValue operation: ALLOW_OVERRIDES, FINAL_VALUE_IGNORE_OVERRIDES, FINAL_VALUE_THROW_ON_OVERRIDE, or APPEND.
- Prefer FINAL_VALUE_IGNORE_OVERRIDES or FINAL_VALUE_THROW_ON_OVERRIDE for org-enforced settings; ALLOW_OVERRIDES when users may override.
- Lint policy files programmatically: assert setValue.behavior != UNDEFINED for every entry before rollout.
Example fix
// before
{"flagName":"compilation_mode","setValue":{"flagValue":["opt"]}}
// after
{"flagName":"compilation_mode","setValue":{"flagValue":["opt"],"behavior":"FINAL_VALUE_IGNORE_OVERRIDES"}} Defensive patterns
Strategy: validation
Validate before calling
// Assert every setValue entry has an explicit behavior
for (FlagPolicy fp : policy.getFlagPoliciesList()) {
if (fp.hasSetValue() && fp.getSetValue().getBehavior() == SetValue.Behavior.UNDEFINED) {
throw new IllegalStateException("setValue for '" + fp.getFlagName() + "' needs an explicit behavior");
}
} Try / catch
Catch OptionsParsingException; treat as a policy file defect — add an explicit behavior enum value and redeploy the policy.
Prevention
- Never omit behavior in setValue entries; proto3 defaults make it UNDEFINED
- Template policies with behavior as a required template variable
- Remember FINAL_VALUE_IGNORE_OVERRIDES vs THROW_ON_OVERRIDE semantics when choosing
When it happens
Trigger: A policy entry with setValue present (and flagValue list non-empty) but behavior omitted, e.g. {"flagName":"...","setValue":{"flagValue":["x"]}} — in proto3 JSON, omitting behavior leaves it at the UNDEFINED enum default.
Common situations: Hand-written policy JSON that only sets flagValue, samples copied from docs that omit the behavior field, protobuf field-name typos (behavior vs behaviour), policy generators that skip defaulted fields.
Related errors
- SetValue operation from invocation policy for %s does not ha
- SetValue operation from invocation policy sets multiple valu
- Flag policy for flag '%s' does not have an operation
- Invocation policy is applied after --config expansion, chang
- Allow_Values on expansion flags like %s is not allowed.
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/f2a8228952e7b1fc.
Report an issue: GitHub.