{"record":{"id":"ff6a75c26866258a","repo":"router-for-me/CLIProxyAPI","slug":"weight-must-be-an-integer-ff6a75","errorCode":null,"errorMessage":"weight must be an integer","messagePattern":"weight must be an integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/credentialweight/weight.go","lineNumber":78,"sourceCode":"\t\t}\n\t\treturn int64(typed), nil\n\tcase uint8:\n\t\treturn int64(typed), nil\n\tcase uint16:\n\t\treturn int64(typed), nil\n\tcase uint32:\n\t\tif uint64(typed) > uint64(Max) {\n\t\t\treturn 0, fmt.Errorf(\"weight must not exceed %d\", Max)\n\t\t}\n\t\treturn int64(typed), nil\n\tcase uint64:\n\t\tif typed > uint64(Max) {\n\t\t\treturn 0, fmt.Errorf(\"weight must not exceed %d\", Max)\n\t\t}\n\t\treturn int64(typed), nil\n\tcase float64:\n\t\tif math.IsNaN(typed) || math.IsInf(typed, 0) || math.Trunc(typed) != typed {\n\t\t\treturn 0, fmt.Errorf(\"weight must be an integer\")\n\t\t}\n\t\tif typed <= 0 {\n\t\t\treturn 0, nil\n\t\t}\n\t\tif typed > float64(Max) {\n\t\t\treturn 0, fmt.Errorf(\"weight must not exceed %d\", Max)\n\t\t}\n\t\treturn int64(typed), nil\n\tcase float32:\n\t\treturn ParseValue(float64(typed))\n\tcase json.Number:\n\t\tweight, errParse := typed.Int64()\n\t\tif errParse != nil {\n\t\t\treturn 0, fmt.Errorf(\"weight must be an integer: %w\", errParse)\n\t\t}\n\t\treturn Normalize(weight)\n\tcase string:\n\t\treturn ParseString(typed)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/credentialweight/weight.go#L60-L96","documentation":"Float-integrity check in credentialweight.ParseValue: a float64 weight must be a finite, integral value (math.Trunc(f) == f, not NaN, not Inf). Fractional or non-finite floats are rejected because weights must be integers.","triggerScenarios":"ParseValue receives a float64 like 2.5, -0.5 (fractional), math.NaN(), or math.Inf(1). Typically happens when JSON metadata is decoded into interface{} and numbers become float64 (the encoding/json default).","commonSituations":"Writing \"weight\": 0.5 (unquoted decimal) in an auth JSON file — encoding/json turns it into float64 and this error fires. Also scientific notation like 1e2 is accepted (integral) but 1.5e0 is not.","solutions":["Use whole numbers in weight metadata: 2 instead of 2.5","If fractional ratios are needed, multiply all weights by a common factor first (0.5/0.5 -> 1/1; 0.7/0.3 -> 7/3)","Round at the producing side and write integers so JSON decodes them as integral float64"],"exampleFix":"// before (auth file)\n{\"weight\": 1.5}\n\n// after (auth file)\n{\"weight\": 3}","handlingStrategy":"validation","validationCode":"func integralFloat(f float64) bool {\n    return !math.IsNaN(f) && !math.IsInf(f, 0) && math.Trunc(f) == f\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write integers (not decimals) in weight JSON metadata — encoding/json makes every number a float64","Convert fractional ratios to whole numbers by scaling (0.7 -> 7) at authoring time","Reject NaN/Inf early if weights pass through any float computation"],"tags":["validation","parsing","go","json","credentialweight"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}