alibaba/nacos · warning · NacosApiException
WEIGHT_ERROR
WEIGHT_ERROR
Error message
instance format invalid: The weights range from %s to %s
What it means
Thrown by ConsoleInstanceController.checkWeight, invoked from updateInstance (PUT /v3/console/ns/instance) when instanceForm.getWeight() is outside the allowed range. The bounds are naming Constants.MIN_WEIGHT_VALUE = 0.0 and MAX_WEIGHT_VALUE = 10000.0. It raises NacosApiException with HTTP 400 and ErrorCode.WEIGHT_ERROR.
Source
Thrown at console/src/main/java/com/alibaba/nacos/console/controller/v3/naming/ConsoleInstanceController.java:132
@Since("3.2.2")
@CanDistro
@DeleteMapping
@TpsControl(pointName = "NamingInstanceDeregister", name = "HttpNamingInstanceDeregister")
@Secured(action = ActionTypes.WRITE, apiType = ApiType.CONSOLE_API)
public Result<String> removeInstance(InstanceForm instanceForm) throws NacosException {
// check param
instanceForm.validate();
checkDeleteInstanceEphemeral(instanceForm.getEphemeral());
// build instance
Instance instance = buildInstance(instanceForm);
instanceProxy.removeInstance(instanceForm, instance);
return Result.success("ok");
}
private 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);
}
}
private void checkDeleteInstanceEphemeral(Boolean ephemeral) throws NacosApiException {
if (Boolean.TRUE.equals(ephemeral)) {
throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),
ErrorCode.PARAMETER_VALIDATE_ERROR,
"Console only supports deregistering persistent instances");
}
}
private Instance buildInstance(InstanceForm instanceForm) throws NacosException {
Instance instance =
InstanceBuilder.newBuilder().setServiceName(buildCompositeServiceName(instanceForm))
.setIp(instanceForm.getIp()).setClusterName(instanceForm.getClusterName())View on GitHub (pinned to 9b989acdf1)
Solutions
- Set instanceForm.setWeight to a value within [0.0, 10000.0] before the PUT.
- Clamp the submitted weight to the legal range in the client UI.
- If you intended a relative weight, remember the default is 1.0 and the max is 10000.0; rescale your input accordingly.
Example fix
// before form.setWeight(50000.0); // exceeds MAX_WEIGHT_VALUE // after form.setWeight(Math.max(0.0, Math.min(10000.0, desiredWeight)));
Defensive patterns
Strategy: validation
Validate before calling
// Clamp weight to the legal range before the PUT
final double MIN = 0.0, MAX = 10000.0;
Double w = instanceForm.getWeight();
if (w == null) { w = 1.0; }
if (w < MIN || w > MAX) {
throw new IllegalArgumentException("weight must be in [0.0, 10000.0], got " + w);
}
instanceForm.setWeight(w); Type guard
// Java: boolean guard for valid weight range
boolean weightOk = instanceForm.getWeight() != null
&& instanceForm.getWeight() >= 0.0
&& instanceForm.getWeight() <= 10000.0; Try / catch
try {
controller.updateInstance(form);
} catch (NacosApiException e) {
if (e.getDetailErrCode() == ErrorCode.WEIGHT_ERROR.getCode()) {
form.setWeight(Math.max(0.0, Math.min(10000.0, form.getWeight())));
controller.updateInstance(form);
} else { throw e; }
} Prevention
- Treat weight as a value in [0.0, 10000.0]; default 1.0.
- Clamp weight in the client UI before submission.
- Add a range assertion in the form's validate().
When it happens
Trigger: Calling PUT /v3/console/ns/instance with a weight less than 0.0 or greater than 10000.0. (Note: updateInstance is the only caller of checkWeight; the DELETE path does not check weight.)
Common situations: Passing a percentage like 100 assuming it is a fraction when Nacos expects a large weight; negative weights from a form bug; a weight scaled by a multiplier that overflows the 10000 cap.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/f28454dd1d7fa12f.
Report an issue: GitHub.