alibaba/nacos · error · NacosException
400
400
Error message
tagv2 gray rule parse failed: key and value's[%s] doesn't match pattern[%s].
What it means
Thrown by MultiTagMatchGrayRule.parse when a sub-expression (after splitting on || and &&) does not contain exactly one '=' separator (keyValueArray.length != 2). Returns NacosException code 400 (INVALID_PARAM). This is a structural error in a multi-tag gray rule expression, distinct from the regex-pattern error 834.
Source
Thrown at config/src/main/java/com/alibaba/nacos/config/server/model/gray/multitag/MultiTagMatchGrayRule.java:82
protected void parse(String rawRule) throws NacosException {
this.isPatternMatch(rawRule, EXPRESSION_PATTERN);
String[] splitSubExpressionByOrArray = rawRule.trim()
.split(MultiTagMatchGrayRule.TagV2GrayRuleJoint.OR_REGEXP.getExpression());
for (String s : splitSubExpressionByOrArray) {
if (StringUtils.isBlank(s)) {
continue;
}
//each subExpression is jointed by one or multi "&&"
String[] splitSubExpressionByAndArray = s.trim()
.split(MultiTagMatchGrayRule.TagV2GrayRuleJoint.AND_REGEXP.getExpression());
for (int andIndex = 0; andIndex < splitSubExpressionByAndArray.length; andIndex++) {
if (StringUtils.isBlank(splitSubExpressionByAndArray[andIndex])) {
continue;
}
String[] keyValueArray =
splitSubExpressionByAndArray[andIndex].trim().split(EQUAL_PATTERN);
if (keyValueArray.length != 2) {
throw new NacosException(NacosException.INVALID_PARAM, String.format(
"tagv2 gray rule parse failed: key and value's[%s] doesn't match pattern[%s].",
splitSubExpressionByAndArray[andIndex],
KEY_PATTERN + EQUAL_PATTERN + VALUE_PATTERN));
}
isPatternMatch(keyValueArray[0].trim(), KEY_PATTERN);
isPatternMatch(keyValueArray[1].trim(), VALUE_PATTERN);
Set<String> values =
Arrays.stream(keyValueArray[1].split(VALUE_SPLITER_PATTERN)).map(String::trim)
.filter(StringUtils::isNotBlank).collect(Collectors.toSet());
MultiTagMatchGrayRule.TagV2GrayRuleItem tagV2GrayRuleItem =
new MultiTagMatchGrayRule.TagV2GrayRuleItem(
keyValueArray[0].trim(), values);
if (andIndex == 0) {
tagV2GrayRuleItem.setJoint(MultiTagMatchGrayRule.TagV2GrayRuleJoint.OR);
}
if (this.ruleItems == null) {
this.ruleItems = new ArrayList<>();
}View on GitHub (pinned to 9b989acdf1)
Solutions
- Ensure every key=value segment in the multi-tag expression has exactly one '='.
- Join multiple conditions with '&&' (AND) or '||' (OR), and separate values within a key with commas.
Example fix
// before grayRuleExp = "zone&&env=prod" // 'zone' has no value // after grayRuleExp = "zone=us-east-1&&env=prod"
Defensive patterns
Strategy: validation
Validate before calling
// Validate multi-tag rule: each segment must have exactly one '='
for (String seg : grayRuleExp.split("\\|\\||&&")) {
seg = seg.trim();
if (seg.isEmpty()) continue;
String[] kv = seg.split("=", -1);
if (kv.length != 2) throw new IllegalArgumentException("bad segment: " + seg);
} Try / catch
try { configApi.publishGray(form); }
catch (NacosException e) {
if (e.getErrCode() == NacosException.INVALID_PARAM)
{ /* each segment needs exactly one '=' */ } else throw e;
} Prevention
- Ensure each key=value segment in multi-tag rules has exactly one '='.
- Join segments with && or ||, values with commas.
When it happens
Trigger: Submitting a multi-tag grayRuleExp where one segment has no '=' (e.g. 'keyonly&&k2=v2') or more than one '=' (e.g. 'a=b=c'). The overall EXPRESSION_PATTERN may pass but the split-by-'=' produces != 2 parts.
Common situations: Building complex multi-tag expressions programmatically with a missing or duplicated '='; concatenating keys without values; using '==' or '!=' instead of '='.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/c73824adbd8754f4.
Report an issue: GitHub.