{"record":{"id":"407f6927c999dbe4","repo":"alibaba/nacos","slug":"weight-error-407f69","errorCode":"WEIGHT_ERROR","errorMessage":"instance format invalid: The weights range from 0.0 to 10000.0","messagePattern":"instance format invalid: The weights range from 0\\.0 to 10000\\.0","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"error","filePath":"naming/src/main/java/com/alibaba/nacos/naming/utils/NamingRequestUtil.java","lineNumber":91,"sourceCode":"    public static String getSourceIpForGrpcRequest(RequestMeta meta) {\n        String sourceIp = getSourceIp();\n        // If can't get from request context, get from grpc request meta.\n        if (StringUtils.isBlank(sourceIp)) {\n            sourceIp = meta.getClientIp();\n        }\n        return sourceIp;\n    }\n    \n    /**\n     * Check request weight is validate.\n     *\n     * @param weight weight from request\n     * @throws NacosException if weight is invalid\n     */\n    public static void checkWeight(Double weight) throws NacosException {\n        if (weight > com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE\n            || weight < com.alibaba.nacos.naming.constants.Constants.MIN_WEIGHT_VALUE) {\n            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.WEIGHT_ERROR,\n                \"instance format invalid: The weights range from \"\n                    + com.alibaba.nacos.naming.constants.Constants.MIN_WEIGHT_VALUE + \" to \"\n                    + com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE);\n        }\n    }\n}\n","sourceCodeStart":73,"sourceCodeEnd":98,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/naming/src/main/java/com/alibaba/nacos/naming/utils/NamingRequestUtil.java#L73-L98","documentation":"Thrown by NamingRequestUtil.checkWeight when the supplied instance weight falls outside [MIN_WEIGHT_VALUE=0.0, MAX_WEIGHT_VALUE=10000.0]. It is a NacosApiException with code WEIGHT_ERROR and HTTP 400 BAD_REQUEST, raised during instance registration or weight updates.","triggerScenarios":"Registering or updating an instance (POST/PUT /v3/admin/ns/instance or /v3/client/ns/instance) with a 'weight' query/body parameter greater than 10000.0 or less than 0.0. Also triggered by SDK registerInstance calls passing an out-of-range Instance.weight.","commonSituations":"Passing weight as a percentage (e.g. 1.0 expecting 1%) when Nacos expects a 0-10000 scale; negative weights from misconfigured load balancers; accidentally sending a percentage fraction that is treated as the raw value.","solutions":["Clamp the instance weight to the [0.0, 10000.0] range before submitting the request.","If you intended a percentage in [0,1] or [0,100], rescale it: nacosWeight = percent * 100 (for 0-100 percent) before sending.","Re-check the API/SDK contract: weight is a double with 0.0 minimum and 10000.0 maximum, not a 0-1 fraction."],"exampleFix":"// before\nInstance inst = new Instance();\ninst.setWeight(-5.0);          // out of range\n\n// after\ninst.setWeight(Math.max(0.0, Math.min(10000.0, desiredWeight)));","handlingStrategy":"validation","validationCode":"public static boolean isValidWeight(Double w) {\n    return w != null\n        && w >= com.alibaba.nacos.naming.constants.Constants.MIN_WEIGHT_VALUE\n        && w <= com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE;\n}\n// call before instance.setWeight / registerInstance","typeGuard":"static boolean isValidWeight(Double w) {\n    return w != null && w >= 0.0 && w <= 10000.0;\n}","tryCatchPattern":null,"preventionTips":["Remember Nacos weight is a 0..10000 double, not a 0..1 fraction.","Clamp at the source (config/SDK wrapper) rather than relying on the server 400.","Unit-test weight boundaries (0.0, 10000.0, just-out-of-range)."],"tags":["naming","instance","weight","validation","bad-request"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}