alibaba/nacos · error · NacosApiException

21006

21006

Error message

not match any type of selector!

What it means

Thrown by ServiceControllerV3.parseSelector with ErrorCode.SELECTOR_ERROR=21006 (HTTP 400 INVALID_PARAM). There are two trigger points: (1) the selector JSON has no 'type' field at all, or (2) selectorManager.parseSelector() returns null because the 'type' value does not match any registered selector type. The registered types are keyed in SelectorManager.selectorTypes (typically 'none' and 'label', plus CMDB-provided types).

Source

Thrown at naming/src/main/java/com/alibaba/nacos/naming/controllers/v3/ServiceControllerV3.java:231

        
        return Result.success("ok");
    }
    
    private Selector parseSelector(String selectorJsonString) throws Exception {
        if (StringUtils.isBlank(selectorJsonString)) {
            return new NoneSelector();
        }
        
        JsonNode selectorJson = JacksonUtils.toObj(URLDecoder.decode(selectorJsonString, "UTF-8"));
        String type = Optional.ofNullable(selectorJson.get("type")).orElseThrow(
            () -> new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SELECTOR_ERROR,
                "not match any type of selector!"))
            .asText();
        String expression =
            Optional.ofNullable(selectorJson.get("expression")).map(JsonNode::asText).orElse(null);
        Selector selector = selectorManager.parseSelector(type, expression);
        if (Objects.isNull(selector)) {
            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SELECTOR_ERROR,
                "not match any type of selector!");
        }
        
        return selector;
    }
    
    /**
     * get subscriber list.
     */
    @Since("3.0.0")
    @GetMapping("/subscribers")
    @Secured(action = ActionTypes.READ, apiType = ApiType.ADMIN_API)
    public Result<Page<SubscriberInfo>> subscribers(ServiceForm serviceForm, PageForm pageForm,
        AggregationForm aggregationForm) throws Exception {
        serviceForm.validate();
        pageForm.validate();
        int pageNo = pageForm.getPageNo();
        int pageSize = pageForm.getPageSize();

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Ensure the selector JSON includes a 'type' field set to a registered value: 'none' for no filtering or 'label' for label-based selection.
  2. If using a CMDB selector, confirm the CMDB plugin is installed and the selector type is registered in SelectorManager.
  3. Validate the selector JSON structure: {"type": "label", "expression": "..."} before sending.
  4. Use a blank/empty selectorJsonString to default to NoneSelector if no selector is needed.

Example fix

// before
String selectorJson = "{\"expression\": \"key=value\"}";

// after
String selectorJson = "{\"type\": \"label\", \"expression\": \"key=value\"}";
Defensive patterns

Strategy: validation

Validate before calling

// validate selector JSON before sending to the server
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(selectorJsonString);
String type = node.has("type") ? node.get("type").asText() : null;
if (type == null || !Set.of("none", "label").contains(type)) {
    throw new IllegalArgumentException("selector type must be 'none' or 'label', got: " + type);
}

Type guard

boolean isValidSelectorType(String type) {
    return type != null && Set.of("none", "label").contains(type.toLowerCase());
}

Prevention

When it happens

Trigger: Calling the service update API with a selectorJsonString that either (a) is a valid JSON object but lacks the 'type' field, or (b) has a 'type' value not in the SelectorManager's selectorTypes map (e.g. 'unknown', 'expression' when no such selector is registered).

Common situations: Using a CMDB selector type when the CMDB plugin is not installed/enabled. Misspelling the selector type (e.g. 'lable' instead of 'label'). Passing malformed selector JSON where the type field is nested incorrectly. Migrating from a version that supported a selector type that was removed.

Related errors


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