alibaba/nacos · error · NacosException

400

400

Error message

tagv2 gray rule parse failed: raw string [%s] doesn't match pattern[%s].

What it means

Thrown by AbstractTagMatchGrayRule.isPatternMatch when the raw gray rule string does not match the expected regex pattern. Returns NacosException code 400 (INVALID_PARAM). The pattern for tag rules is key=value(s) where key matches [a-zA-Z0-9-_:\.]+ and value matches the same class optionally comma-separated. This is the base check inherited by both single-tag and multi-tag rules.

Source

Thrown at config/src/main/java/com/alibaba/nacos/config/server/model/gray/AbstractTagMatchGrayRule.java:48

    
    protected static final String KEY_PATTERN = "[a-zA-Z0-9-_:\\.]+";
    
    protected static final String VALUE_SPLITER_PATTERN = ",";
    
    protected static final String VALUE_PATTERN =
        KEY_PATTERN + "(\\s*" + VALUE_SPLITER_PATTERN + "\\s*" + KEY_PATTERN + ")*";
    
    public AbstractTagMatchGrayRule() {
        super();
    }
    
    public AbstractTagMatchGrayRule(String rawGrayRuleExp, int priority) {
        super(rawGrayRuleExp, priority);
    }
    
    protected void isPatternMatch(String rawString, String pattern) throws NacosException {
        if (!rawString.matches(pattern)) {
            throw new NacosException(NacosException.INVALID_PARAM,
                String.format(
                    "tagv2 gray rule parse failed: " + "raw string [%s] doesn't match pattern[%s].",
                    rawString, pattern));
        }
    }
    
    /**
     * Check whether another tag match gray rule has the same expression, priority, type and version.
     *
     * @param obj another object.
     * @return true if equals.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj instanceof AbstractTagMatchGrayRule) {

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Ensure the rule expression matches key=value format with only allowed characters [a-zA-Z0-9-_:\.] in keys and values.
  2. For multi-value rules use comma separation: key=v1,v2,v3.
  3. Validate the expression against the KEY_PATTERN and VALUE_PATTERN regex before submitting.

Example fix

// before
grayRuleExp = "zone = us east 1"  // spaces and missing pattern
// after
grayRuleExp = "zone=us-east-1"
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern RULE =
    Pattern.compile("^[a-zA-Z0-9-_:\\.]+=[a-zA-Z0-9-_:\\.]+(,[a-zA-Z0-9-_:\\.]+)*$");
if (!RULE.matcher(grayRuleExp.trim()).matches()) {
    throw new IllegalArgumentException("invalid tag gray rule expression");
}

Try / catch

try { configApi.publishGray(form); }
catch (NacosException e) {
    if (e.getErrCode() == NacosException.INVALID_PARAM)
        { /* fix rule expression */ } else throw e;
}

Prevention

When it happens

Trigger: Publishing a tag gray config whose grayRuleExp contains characters outside [a-zA-Z0-9-_:\.], or whose structure (key=value) is malformed — e.g. missing '=' , empty key, or special symbols in values. Triggered during rule parsing when the gray is published.

Common situations: Rule expression built from unescaped user input containing spaces or symbols; copy-paste from a non-tag rule type; mismatched grayType (using a single-tag expression for multi-tag).

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/264cf77141c7c856. Report an issue: GitHub.