{"record":{"id":"8b394367ae4c74dd","repo":"alibaba/nacos","slug":"21004","errorCode":"21004","errorMessage":"service not found, namespace: {namespaceId}, service: {service}","messagePattern":"service not found, namespace: (.+?), service: (.+?)","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"error","filePath":"naming/src/main/java/com/alibaba/nacos/naming/core/InstanceOperatorClientImpl.java","lineNumber":135,"sourceCode":"        String clientId = IpPortBasedClient.getClientId(instance.toInetAddr(), ephemeral);\n        if (!clientManager.contains(clientId)) {\n            Loggers.SRV_LOG.warn(\"remove instance from non-exist client: {}\", clientId);\n            return;\n        }\n        Service service = Service.newService(namespaceId, groupName, serviceName, ephemeral);\n        clientOperationService.deregisterInstance(service, instance, clientId);\n    }\n    \n    @Override\n    public void updateInstance(String namespaceId, String groupName, String serviceName,\n        Instance instance)\n        throws NacosException {\n        NamingUtils.checkInstanceIsLegal(instance);\n        \n        Service service =\n            Service.newService(namespaceId, groupName, serviceName, instance.isEphemeral());\n        if (!ServiceManager.getInstance().containSingleton(service)) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,\n                \"service not found, namespace: \" + namespaceId + \", service: \" + service);\n        }\n        String metadataId = InstancePublishInfo.genMetadataId(instance.getIp(), instance.getPort(),\n            instance.getClusterName());\n        metadataOperateService.updateInstanceMetadata(service, metadataId, buildMetadata(instance));\n        NotifyCenter.publishEvent(new InfoChangeEvent.InstanceInfoChangeEvent(service, instance));\n    }\n    \n    private InstanceMetadata buildMetadata(Instance instance) {\n        InstanceMetadata result = new InstanceMetadata();\n        result.setEnabled(instance.isEnabled());\n        result.setWeight(instance.getWeight());\n        result.getExtendData().putAll(filterNullValue(instance.getMetadata()));\n        return result;\n    }\n    \n    private Map<String, String> filterNullValue(Map<String, String> metadata) {\n        return metadata.entrySet().stream().filter(entry -> entry.getValue() != null)","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/naming/src/main/java/com/alibaba/nacos/naming/core/InstanceOperatorClientImpl.java#L117-L153","documentation":"Thrown by InstanceOperatorClientImpl.updateInstance when the target service does not exist in the ServiceManager singleton registry. Uses INVALID_PARAM=400 (HTTP) with ErrorCode.INSTANCE_ERROR=21004. The service must already be registered before an instance can be updated. Note the message includes namespaceId and the Service object (which includes the grouped name).","triggerScenarios":"Calling updateInstance(namespaceId, groupName, serviceName, instance) for a service where ServiceManager.containSingleton returns false. The instance update path requires the service to pre-exist because it writes instance metadata keyed by the service.","commonSituations":"Updating an instance for a service that was never registered (instances are typically registered, not 'updated', for new services). Service was deleted between register and update. Wrong namespace/group/service name. Ephemeral/persistent flag mismatch — the service was registered with a different ephemeral value than the instance.","solutions":["Register the service and at least one instance first, then use updateInstance.","Verify the service exists with the matching ephemeral flag (the Service is created with instance.isEphemeral()).","Check namespaceId, groupName, and serviceName for correctness.","If the service was deleted, re-register it before updating instances."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Service svc = Service.newService(namespaceId, groupName, serviceName, instance.isEphemeral());\nif (!ServiceManager.getInstance().containSingleton(svc)) {\n    throw new IllegalStateException(\n        \"Cannot update instance: service \" + groupName + \"/\" + serviceName\n        + \" (ephemeral=\" + instance.isEphemeral() + \") not found\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    instanceOperator.updateInstance(namespaceId, groupName, serviceName, instance);\n} catch (NacosApiException e) {\n    if (ErrorCode.INSTANCE_ERROR.getCode() == e.getErrCode()\n            && e.getMessage().contains(\"service not found\")) {\n        // register the service/instance first, then retry the update\n    } else { throw e; }\n}","preventionTips":["Register the service and at least one instance before calling updateInstance.","Ensure the instance's ephemeral flag matches the registered service's ephemeral flag.","Verify namespace, group, and service name before attempting instance updates."],"tags":["naming","instance","not-found","validation","admin-api"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}