alibaba/nacos · error · NacosException
SERVER_ERROR
SERVER_ERROR
Error message
Selector parses failed: %s
What it means
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.
Source
Thrown at naming/src/main/java/com/alibaba/nacos/naming/selector/SelectorManager.java:157
* @return {@link Selector}.
*/
public Selector parseSelector(String type, String condition) throws NacosException {
if (StringUtils.isBlank(type)) {
return null;
}
Class<? extends Selector> clazz = selectorTypes.get(type);
if (Objects.isNull(clazz)) {
return null;
}
try {
Selector selector = clazz.newInstance();
selector.parse(condition);
return selector;
} catch (Exception e) {
Loggers.SRV_LOG.warn(
"[SelectorManager] Parse Selector failed, type: {}, condition: {}.", type,
condition, e);
throw new NacosException(SERVER_ERROR, "Selector parses failed: " + e.getMessage());
}
}
/**
* invoke the {@link Selector#select(Object)}. it will help {@link Selector} to build the context it need.
*
* @param selector {@link Selector}.
* @param consumerIp the consumer Ip address.
* @param providers the provider list for select.
* @return the select instance list.
*/
public <T extends Instance> List<T> select(Selector selector, String consumerIp,
List<T> providers) {
if (Objects.isNull(selector)) {
return providers;
}
SelectorContextBuilder selectorContextBuilder =
contextBuilders.get(selector.getContextType());View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before: malformed condition for a label selector
selectorManager.parseSelector("label", "env=prod,");
// after: valid label condition
selectorManager.parseSelector("label", "{\"env\":\"prod\"}"); Defensive patterns
Strategy: try-catch
Validate before calling
if (StringUtils.isBlank(type)) { return null; }
if (!selectorManager.getAllSelectorTypes().contains(type)) { return null; }
// validate condition grammar for the selector type before parseSelector
// e.g. for label selector: new JSONObject(condition); Type guard
static boolean isParsableSelector(SelectorManager sm, String type, String condition) {
return type != null && sm.getAllSelectorTypes().contains(type) && condition != null;
} Try / catch
try {
Selector s = selectorManager.parseSelector(type, condition);
} catch (NacosException e) {
// code == SERVER_ERROR && message starts with "Selector parses failed"
log.warn("selector parse failed for type={}, condition={}", type, condition, e);
// fall back to no selector (null) or reject the request upstream
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/0d6fd53b31701491.
Report an issue: GitHub.