{"record":{"id":"6b4c482b579cbf91","repo":"router-for-me/CLIProxyAPI","slug":"weight-is-missing","errorCode":null,"errorMessage":"weight is missing","messagePattern":"weight is missing","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"internal/api/handlers/management/config_lists.go","lineNumber":15,"sourceCode":"package management\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/router-for-me/CLIProxyAPI/v7/internal/config\"\n)\n\nfunc parseCredentialWeightPatch(raw json.RawMessage) (*int, error) {\n\tif len(raw) == 0 {\n\t\treturn nil, fmt.Errorf(\"weight is missing\")\n\t}\n\tif bytes.Equal(bytes.TrimSpace(raw), []byte(\"null\")) {\n\t\treturn nil, nil\n\t}\n\tvar weight int\n\tdecoder := json.NewDecoder(bytes.NewReader(raw))\n\tif errDecode := decoder.Decode(&weight); errDecode != nil {\n\t\treturn nil, fmt.Errorf(\"weight must be an integer\")\n\t}\n\tif errValidate := config.ValidateCredentialWeight(&weight); errValidate != nil {\n\t\treturn nil, errValidate\n\t}\n\treturn &weight, nil\n}\n\nfunc rejectInvalidCredentialWeight(c *gin.Context, field string, weight *int) bool {\n\tif errValidate := config.ValidateCredentialWeight(weight); errValidate != nil {\n\t\tc.JSON(400, gin.H{\"error\": fmt.Sprintf(\"%s: %v\", field, errValidate)})","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/handlers/management/config_lists.go#L1-L33","documentation":"parseCredentialWeightPatch received an empty json.RawMessage for the weight field — the key was present in the request shape but carried zero-length raw bytes, i.e. no JSON value at all. Since explicit null is handled separately (meaning 'clear weight'), an empty raw payload is treated as a malformed request rather than a clear.","triggerScenarios":"PATCH to a credential-list endpoint whose JSON body or field extraction produced an empty weight fragment — a client sending {\"weight\":} (invalid JSON accepted by a lenient layer) or calling code building the patch map with an empty RawMessage.","commonSituations":"Client libraries serializing undefined or absent values into empty raw bytes; hand-crafted curl bodies with malformed JSON; an intermediary proxy stripping the value.","solutions":["Send a complete body: {\"weight\": 3} to set, {\"weight\": null} to clear, or omit the key entirely","Validate the JSON before sending (most HTTP clients reject {\"weight\":} at parse time)","If writing calling code, only include weight in the patch map when a value exists","Retry with the corrected payload"],"exampleFix":"# before\ncurl -X PATCH .../gemini-key/0 -d '{\"weight\":}'\n# after\ncurl -X PATCH .../gemini-key/0 -d '{\"weight\": 3}'","handlingStrategy":"validation","validationCode":"if len(rawWeight) == 0 { /* omit weight from the patch body instead of sending empty */ }","typeGuard":"func isSendableWeight(raw json.RawMessage) bool { return len(raw) > 0 }","tryCatchPattern":null,"preventionTips":["Build patch bodies with omitempty on optional fields","Use null explicitly when clearing a weight"],"tags":["validation","json","user-input","patch"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}