{"record":{"id":"f28454dd1d7fa12f","repo":"alibaba/nacos","slug":"weight-error","errorCode":"WEIGHT_ERROR","errorMessage":"instance format invalid: The weights range from %s to %s","messagePattern":"instance format invalid: The weights range from (.+?) to (.+?)","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"warning","filePath":"console/src/main/java/com/alibaba/nacos/console/controller/v3/naming/ConsoleInstanceController.java","lineNumber":132,"sourceCode":"    @Since(\"3.2.2\")\n    @CanDistro\n    @DeleteMapping\n    @TpsControl(pointName = \"NamingInstanceDeregister\", name = \"HttpNamingInstanceDeregister\")\n    @Secured(action = ActionTypes.WRITE, apiType = ApiType.CONSOLE_API)\n    public Result<String> removeInstance(InstanceForm instanceForm) throws NacosException {\n        // check param\n        instanceForm.validate();\n        checkDeleteInstanceEphemeral(instanceForm.getEphemeral());\n        // build instance\n        Instance instance = buildInstance(instanceForm);\n        instanceProxy.removeInstance(instanceForm, instance);\n        return Result.success(\"ok\");\n    }\n    \n    private 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    private void checkDeleteInstanceEphemeral(Boolean ephemeral) throws NacosApiException {\n        if (Boolean.TRUE.equals(ephemeral)) {\n            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                ErrorCode.PARAMETER_VALIDATE_ERROR,\n                \"Console only supports deregistering persistent instances\");\n        }\n    }\n    \n    private Instance buildInstance(InstanceForm instanceForm) throws NacosException {\n        Instance instance =\n            InstanceBuilder.newBuilder().setServiceName(buildCompositeServiceName(instanceForm))\n                .setIp(instanceForm.getIp()).setClusterName(instanceForm.getClusterName())","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console/src/main/java/com/alibaba/nacos/console/controller/v3/naming/ConsoleInstanceController.java#L114-L150","documentation":"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.","triggerScenarios":"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.)","commonSituations":"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.","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."],"exampleFix":"// before\nform.setWeight(50000.0); // exceeds MAX_WEIGHT_VALUE\n\n// after\nform.setWeight(Math.max(0.0, Math.min(10000.0, desiredWeight)));","handlingStrategy":"validation","validationCode":"// Clamp weight to the legal range before the PUT\nfinal double MIN = 0.0, MAX = 10000.0;\nDouble w = instanceForm.getWeight();\nif (w == null) { w = 1.0; }\nif (w < MIN || w > MAX) {\n    throw new IllegalArgumentException(\"weight must be in [0.0, 10000.0], got \" + w);\n}\ninstanceForm.setWeight(w);","typeGuard":"// Java: boolean guard for valid weight range\nboolean weightOk = instanceForm.getWeight() != null\n    && instanceForm.getWeight() >= 0.0\n    && instanceForm.getWeight() <= 10000.0;","tryCatchPattern":"try {\n    controller.updateInstance(form);\n} catch (NacosApiException e) {\n    if (e.getDetailErrCode() == ErrorCode.WEIGHT_ERROR.getCode()) {\n        form.setWeight(Math.max(0.0, Math.min(10000.0, form.getWeight())));\n        controller.updateInstance(form);\n    } else { throw e; }\n}","preventionTips":["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()."],"tags":["validation","naming","instance","weight"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}