bazelbuild/bazel · error · OptionsParsingException
Malformed value of --invocation_policy:
Error message
Malformed value of --invocation_policy:
What it means
Thrown by InvocationPolicyParser.parse when the value passed to --invocation_policy cannot be interpreted as either a base64-encoded binary InvocationPolicy proto or a text-format InvocationPolicy proto. The parser first strips all whitespace and attempts base64+binary-proto decoding; only if that fails does it fall back to text-format parsing. If both paths raise, the raw policy string is reported as malformed.
Source
Thrown at src/main/java/com/google/devtools/common/options/InvocationPolicyParser.java:52
* --invocation_policy is invalid.
*/
public static InvocationPolicy parsePolicy(String policy) throws OptionsParsingException {
if (Strings.isNullOrEmpty(policy)) {
return InvocationPolicy.getDefaultInstance();
}
try {
try {
// First try decoding the policy as a base64 encoded binary proto.
return InvocationPolicy.parseFrom(
BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(policy)));
} catch (IllegalArgumentException e) {
// If the flag value can't be decoded from base64, try decoding the policy as a text
// formatted proto.
return TextFormat.parse(policy, InvocationPolicy.class);
}
} catch (InvalidProtocolBufferException | TextFormat.ParseException e) {
throw new OptionsParsingException("Malformed value of --invocation_policy: " + policy, e);
}
}
}
View on GitHub (pinned to e6e199d060)
Solutions
- Validate the policy offline first: load it as text-format proto with TextFormat.merge into InvocationPolicy, or use a generated Java/Python proto to serialize and then base64-encode it
- If using text format, check field names against invocation_policy.proto and fix typos/quotes
- If passing binary, ensure the value is BaseEncoding.base64() of the serialized proto with whitespace removed
- Print the exact flag value received (it is echoed in the exception message) to spot shell escaping issues
Example fix
# before
bazel --invocation_policy='flag_value { name: "compilation_mode" value: "opt" }' build
# after (valid text format uses set_value)
bazel --invocation_policy='flag_settings { flag: "compilation_mode" set_value: "opt" }' build Defensive patterns
Strategy: validation
Validate before calling
// Java: validate an invocation policy before passing it to Bazel
import com.google.protobuf.TextFormat;
import com.google.devtools.build.lib.runtime.InvocationPolicy;
boolean isValidPolicy(String policy) {
try {
InvocationPolicy.Builder b = InvocationPolicy.newBuilder();
TextFormat.merge(policy, b);
b.build(); // throws on unknown fields / type mismatches
return true;
} catch (Exception e) {
return false;
}
} Try / catch
Catch OptionsParsingException at the call site of InvocationPolicyParser.parse and report the invalid flag value plus cause (InvalidProtocolBufferException/ParseException) to the user instead of the raw stack.
Prevention
- Generate policies programmatically via the proto builder and pass base64, never hand-edit strings
- Keep the invocation_policy.proto schema version in lockstep with the Bazel version under test
- Pipe policies through protoc/text-format validation in CI before deployment
When it happens
Trigger: Calling InvocationPolicyParser.parse(policy) (or launching Bazel with --invocation_policy=...) with a string that is neither valid base64 of a binary proto nor a valid text-format proto, e.g. a typo'd field name, a policy copied with smart quotes, or binary-proto bytes that are not base64.
Common situations: Hand-writing a text-format invocation policy and misspelling a field; passing a policy generated for a different proto schema/version; feeding raw binary bytes instead of base64; trailing shell interpolation mangling the value.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Tried to expand option too many times
- Unrecognized arguments:
- Invalid options syntax: %s Note: Negative target patterns ca
- Invalid options syntax: %s
- Illegal use of 'no' prefix on non-boolean option: %s
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/b2c71e5738d1ca57.
Report an issue: GitHub.