{"record":{"id":"f976374d9051b77c","repo":"alibaba/nacos","slug":"selector-error","errorCode":"SELECTOR_ERROR","errorMessage":"not match any type of selector!","messagePattern":"not match any type of selector!","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"warning","filePath":"console/src/main/java/com/alibaba/nacos/console/controller/v3/naming/ConsoleServiceController.java","lineNumber":266,"sourceCode":"            clusterMetadata);\n        return Result.success(\"ok\");\n    }\n    \n    private Selector parseSelector(String selectorJsonString) throws Exception {\n        if (StringUtils.isBlank(selectorJsonString)) {\n            return new NoneSelector();\n        }\n        \n        JsonNode selectorJson = JacksonUtils.toObj(URLDecoder.decode(selectorJsonString, \"UTF-8\"));\n        String type = Optional.ofNullable(selectorJson.get(\"type\")).orElseThrow(\n            () -> new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SELECTOR_ERROR,\n                \"not match any type of selector!\"))\n            .asText();\n        String expression =\n            Optional.ofNullable(selectorJson.get(\"expression\")).map(JsonNode::asText).orElse(null);\n        Selector selector = selectorManager.parseSelector(type, expression);\n        if (Objects.isNull(selector)) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.SELECTOR_ERROR,\n                \"not match any type of selector!\");\n        }\n        return selector;\n    }\n}\n","sourceCodeStart":248,"sourceCodeEnd":272,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console/src/main/java/com/alibaba/nacos/console/controller/v3/naming/ConsoleServiceController.java#L248-L272","documentation":"Thrown by ConsoleServiceController during service-selector parsing when the selector JSON has no 'type' field, or when selectorManager.parseSelector(type, expression) returns null for an unrecognized type. It raises NacosApiException with NacosException.INVALID_PARAM (HTTP 400) and ErrorCode.SELECTOR_ERROR.","triggerScenarios":"Creating/updating a service with a selector JSON string that is missing 'type', or whose 'type' does not correspond to any selector type the selectorManager knows (e.g., a type not returned by getSelectorTypeList).","commonSituations":"Hand-built selector JSON missing the type key; typo in the type value; using a selector type from a plugin that is not installed/enabled on this cluster.","solutions":["Ensure the selector JSON contains a 'type' field matching an installed selector type (call the selector-type list endpoint to see valid values).","If no selector is wanted, pass the empty/null selector so the NoneSelector branch is used instead of malformed JSON.","Validate the JSON is well formed and URL-decoded correctly before submission."],"exampleFix":"// before\nselectorJsonString = \"{\\\"expression\\\":\\\"...\\\"}\"; // no type\n\n// after\nselectorJsonString = \"{\\\"type\\\":\\\"label\\\",\\\"expression\\\":\\\"...\\\"}\";","handlingStrategy":"validation","validationCode":"// Validate selector JSON before submitting it\nif (selectorJsonString != null && !selectorJsonString.isBlank()) {\n    JsonNode node = JacksonUtils.toObj(URLDecoder.decode(selectorJsonString, \"UTF-8\"));\n    if (node.get(\"type\") == null || node.get(\"type\").asText().isBlank()) {\n        throw new IllegalArgumentException(\"selector JSON must include a non-empty 'type'\");\n    }\n}","typeGuard":"// Java: guard that a selector type is present and known\nboolean selectorValid = selectorNode.hasNonNull(\"type\")\n    && knownSelectorTypes.contains(selectorNode.get(\"type\").asText());","tryCatchPattern":"try {\n    controller.createService(form);\n} catch (NacosApiException e) {\n    if (e.getDetailErrCode() == ErrorCode.SELECTOR_ERROR.getCode()) {\n        form.setSelector(null); // fall back to NoneSelector\n        controller.createService(form);\n    } else { throw e; }\n}","preventionTips":["Fetch valid selector types via the selector-type list endpoint before submitting.","Include a 'type' field in every non-empty selector JSON.","Send an empty/null selector when no routing is needed."],"tags":["validation","naming","selector","service"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}