alibaba/nacos · error · NacosApiException

400

400

Error message

Required parameter 'name' type String is not present

What it means

Thrown by Service.validate() (a NacosApiException, HTTP 400, ErrorCode.PARAMETER_MISSING) when the Service.name field is blank. fillDefaultValue() runs first and fills in defaults for namespaceId and groupName, but name is the primary registry identifier and must be supplied by the caller.

Source

Thrown at api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java:128

    }
    
    public void addMetadata(String key, String value) {
        this.metadata.put(key, value);
    }
    
    public Selector getSelector() {
        return selector;
    }
    
    public void setSelector(Selector selector) {
        this.selector = selector;
    }
    
    @Override
    public void validate() throws NacosApiException {
        fillDefaultValue();
        if (StringUtils.isBlank(name)) {
            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
                "Required parameter 'name' type String is not present");
        }
    }
    
    /**
     * fill default value.
     */
    public void fillDefaultValue() {
        if (StringUtils.isBlank(namespaceId)) {
            namespaceId = Constants.DEFAULT_NAMESPACE_ID;
        }
        if (StringUtils.isBlank(groupName)) {
            groupName = Constants.DEFAULT_GROUP;
        }
    }
}

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Call service.setName("...") with a non-blank value before register/create/validate.
  2. Validate user input at the controller/form boundary so blank names never reach the API.
  3. If building Service from JSON, confirm the name field is present and non-empty after parsing.

Example fix

// before
Service s = new Service();
s.setGroupName("DEFAULT_GROUP");
namingService.createService(s);  // throws 540

// after
Service s = new Service();
s.setName("order-service");
s.setGroupName("DEFAULT_GROUP");
namingService.createService(s);
Defensive patterns

Strategy: validation

Validate before calling

if (service == null || StringUtils.isBlank(service.getName())) {
    throw new IllegalArgumentException("service.name is required");
}

Try / catch

try {
    service.validate();
} catch (NacosApiException e) {
    if (e.getErrCode() == NacosException.INVALID_PARAM
            && e.getMessage().contains("'name'")) {
        // surface a user-friendly 'service name required' error
    }
}

Prevention

When it happens

Trigger: Calling NamingService.registerInstance / service create or update with a Service POJO whose name was never set; submitting an admin/console create-service form with an empty serviceName field; constructing Service from deserialized JSON where the name key was dropped.

Common situations: Console form validation gap; client code building a Service from untrusted user input without checking the name; migration or copy-paste that loses the setName call.

Related errors


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