{"record":{"id":"0d6fd53b31701491","repo":"alibaba/nacos","slug":"server-error-0d6fd5","errorCode":"SERVER_ERROR","errorMessage":"Selector parses failed: %s","messagePattern":"Selector parses failed: (.+?)","errorType":"exception","errorClass":"NacosException","httpStatus":null,"severity":"error","filePath":"naming/src/main/java/com/alibaba/nacos/naming/selector/SelectorManager.java","lineNumber":157,"sourceCode":"     * @return {@link Selector}.\n     */\n    public Selector parseSelector(String type, String condition) throws NacosException {\n        if (StringUtils.isBlank(type)) {\n            return null;\n        }\n        Class<? extends Selector> clazz = selectorTypes.get(type);\n        if (Objects.isNull(clazz)) {\n            return null;\n        }\n        try {\n            Selector selector = clazz.newInstance();\n            selector.parse(condition);\n            return selector;\n        } catch (Exception e) {\n            Loggers.SRV_LOG.warn(\n                \"[SelectorManager] Parse Selector failed, type: {}, condition: {}.\", type,\n                condition, e);\n            throw new NacosException(SERVER_ERROR, \"Selector parses failed: \" + e.getMessage());\n        }\n    }\n    \n    /**\n     * invoke the {@link Selector#select(Object)}. it will help {@link Selector} to build the context it need.\n     *\n     * @param selector {@link Selector}.\n     * @param consumerIp the consumer Ip address.\n     * @param providers the provider list for select.\n     * @return the select instance list.\n     */\n    public <T extends Instance> List<T> select(Selector selector, String consumerIp,\n        List<T> providers) {\n        if (Objects.isNull(selector)) {\n            return providers;\n        }\n        SelectorContextBuilder selectorContextBuilder =\n            contextBuilders.get(selector.getContextType());","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/naming/src/main/java/com/alibaba/nacos/naming/selector/SelectorManager.java#L139-L175","documentation":"Thrown by SelectorManager.parseSelector when a Selector implementation's parse(condition) call raises any exception. The method looks up a Selector subclass by type, instantiates it reflectively, then calls parse() with the caller-supplied condition string; any failure is wrapped as a NacosException with code SERVER_ERROR. The original cause is logged at WARN by SRV_LOG and appended to the message.","triggerScenarios":"Calling parseSelector with a known selector type (e.g. a registered label/expression selector) but a malformed condition string for that type. For example passing non-JSON to a label selector, or an unparseable expression to a none/label selector when registering or querying a service that carries a selector.","commonSituations":"Service registration or discovery requests that include a 'selector' field whose 'type' is recognized but whose 'condition' is malformed; copying a selector JSON with truncated conditions; switching selector implementations where the condition grammar differs.","solutions":["Inspect the logged WARN line '[SelectorManager] Parse Selector failed, type: {}, condition: {}.' which prints the exact type and condition and the underlying exception stacktrace.","Correct the selector 'condition' string to match the grammar expected by the selector type, then resend the request.","If the type is unknown the method returns null (no throw); if you still see this error the type IS registered, so focus on the condition format, not on registering the selector."],"exampleFix":"// before: malformed condition for a label selector\nselectorManager.parseSelector(\"label\", \"env=prod,\");\n\n// after: valid label condition\nselectorManager.parseSelector(\"label\", \"{\\\"env\\\":\\\"prod\\\"}\");","handlingStrategy":"try-catch","validationCode":"if (StringUtils.isBlank(type)) { return null; }\nif (!selectorManager.getAllSelectorTypes().contains(type)) { return null; }\n// validate condition grammar for the selector type before parseSelector\n// e.g. for label selector: new JSONObject(condition);","typeGuard":"static boolean isParsableSelector(SelectorManager sm, String type, String condition) {\n    return type != null && sm.getAllSelectorTypes().contains(type) && condition != null;\n}","tryCatchPattern":"try {\n    Selector s = selectorManager.parseSelector(type, condition);\n} catch (NacosException e) {\n    // code == SERVER_ERROR && message starts with \"Selector parses failed\"\n    log.warn(\"selector parse failed for type={}, condition={}\", type, condition, e);\n    // fall back to no selector (null) or reject the request upstream\n}","preventionTips":["Validate the selector condition against its type's grammar before calling parseSelector.","Treat a null return from parseSelector as 'unknown type' and a thrown exception as 'bad condition'.","Keep a registry of selector types and their condition schemas for client-side validation."],"tags":["naming","selector","server-error","parse"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}