alibaba/nacos · error · NacosApiException
WEIGHT_ERROR
WEIGHT_ERROR
Error message
instance format invalid: The weights range from 0.0 to 10000.0
What it means
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.
Source
Thrown at naming/src/main/java/com/alibaba/nacos/naming/utils/NamingRequestUtil.java:91
public static String getSourceIpForGrpcRequest(RequestMeta meta) {
String sourceIp = getSourceIp();
// If can't get from request context, get from grpc request meta.
if (StringUtils.isBlank(sourceIp)) {
sourceIp = meta.getClientIp();
}
return sourceIp;
}
/**
* Check request weight is validate.
*
* @param weight weight from request
* @throws NacosException if weight is invalid
*/
public static void checkWeight(Double weight) throws NacosException {
if (weight > com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE
|| weight < com.alibaba.nacos.naming.constants.Constants.MIN_WEIGHT_VALUE) {
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.WEIGHT_ERROR,
"instance format invalid: The weights range from "
+ com.alibaba.nacos.naming.constants.Constants.MIN_WEIGHT_VALUE + " to "
+ com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE);
}
}
}
View on GitHub (pinned to 9b989acdf1)
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.
Example fix
// before Instance inst = new Instance(); inst.setWeight(-5.0); // out of range // after inst.setWeight(Math.max(0.0, Math.min(10000.0, desiredWeight)));
Defensive patterns
Strategy: validation
Validate before calling
public static boolean isValidWeight(Double w) {
return w != null
&& w >= com.alibaba.nacos.naming.constants.Constants.MIN_WEIGHT_VALUE
&& w <= com.alibaba.nacos.naming.constants.Constants.MAX_WEIGHT_VALUE;
}
// call before instance.setWeight / registerInstance Type guard
static boolean isValidWeight(Double w) {
return w != null && w >= 0.0 && w <= 10000.0;
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/407f6927c999dbe4.
Report an issue: GitHub.