alibaba/nacos · error · NacosException
400
400
Error message
gray rule parse failed: raw rule[%s] doesn't match pattern[%s].
What it means
Thrown by SingleTagMatchGrayRule.parse when the raw rule does not split into exactly 2 parts on '=' (keyValueArray.length != KEY_VALUE_ARRAY_LENGTH). Returns NacosException code 400 (INVALID_PARAM). Single-tag rules accept only 'key=value1,value2,value3' — no && or || operators.
Source
Thrown at config/src/main/java/com/alibaba/nacos/config/server/model/gray/singletag/SingleTagMatchGrayRule.java:64
public SingleTagMatchGrayRule() {
super();
}
public SingleTagMatchGrayRule(String rawGrayRuleExp, int priority) {
super(rawGrayRuleExp, priority);
}
/**
* parse rule, accept key=value1,value2,value3.
*
* @param rawRule raw rule
*/
@Override
protected void parse(String rawRule) throws NacosException {
this.isPatternMatch(rawRule, EXPRESSION_PATTERN);
String[] keyValueArray = rawRule.trim().split(EQUAL_PATTERN);
if (keyValueArray.length != KEY_VALUE_ARRAY_LENGTH) {
throw new NacosException(NacosException.INVALID_PARAM, String.format(
"gray rule parse failed: raw rule[%s] doesn't match pattern[%s].",
rawRule, KEY_PATTERN + EQUAL_PATTERN + VALUE_PATTERN));
}
isPatternMatch(keyValueArray[0].trim(), KEY_PATTERN);
isPatternMatch(keyValueArray[1].trim(), VALUE_PATTERN);
this.tagKey = keyValueArray[0].trim();
this.tagValueSet = Arrays.stream(keyValueArray[1].trim().split(VALUE_SPLITER_PATTERN))
.map(String::trim).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
}
@Override
public boolean match(Map<String, String> labels) {
if (labels.containsKey(tagKey) && tagValueSet.contains(labels.get(tagKey))) {
return true;
}
return false;
}
View on GitHub (pinned to 9b989acdf1)
Solutions
- For single-tag rules use exactly 'key=value' or 'key=v1,v2,v3' format with exactly one '='.
- If you need AND/OR logic, use the multi-tag grayType instead.
- Validate the expression has exactly one '=' before submitting.
Example fix
// before grayRuleExp = "zone=us-east-1&&env=prod" // operators not allowed in single-tag // after (single-tag) grayRuleExp = "zone=us-east-1" // or switch grayType to multi-tag for AND/OR
Defensive patterns
Strategy: validation
Validate before calling
// Single-tag rule: exactly one '=' no && or ||
String[] kv = rawRule.split("=", -1);
if (kv.length != 2 || rawRule.contains("&&") || rawRule.contains("||")) {
throw new IllegalArgumentException("invalid single-tag rule: " + rawRule);
} Try / catch
try { configApi.publishGray(form); }
catch (NacosException e) {
if (e.getErrCode() == NacosException.INVALID_PARAM)
{ /* single-tag needs key=value only */ } else throw e;
} Prevention
- Use single-tag rules only for one key=value (optionally comma-values).
- Switch to multi-tag grayType for AND/OR logic.
When it happens
Trigger: Submitting a single-tag grayRuleExp with no '=' or multiple '=', or attempting to use multi-tag operators (&&, ||) in a single-tag rule context.
Common situations: Wrong grayType selected (single-tag vs multi-tag); expression with operators intended for multi-tag; malformed key=value.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/668f52049dcf9f42.
Report an issue: GitHub.