{"record":{"id":"31baaf1d5963cf87","repo":"router-for-me/CLIProxyAPI","slug":"weight-must-be-an-integer-w","errorCode":null,"errorMessage":"weight must be an integer: %w","messagePattern":"weight must be an integer: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/credentialweight/weight.go","lineNumber":39,"sourceCode":"func Normalize(weight int64) (int64, error) {\n\tif weight <= 0 {\n\t\treturn 0, nil\n\t}\n\tif weight > Max {\n\t\treturn 0, fmt.Errorf(\"weight must not exceed %d\", Max)\n\t}\n\treturn weight, nil\n}\n\n// ParseString parses a scheduler attribute. An empty value uses the default weight.\nfunc ParseString(raw string) (int64, error) {\n\traw = strings.TrimSpace(raw)\n\tif raw == \"\" {\n\t\treturn Default, nil\n\t}\n\tweight, errParse := strconv.ParseInt(raw, 10, 64)\n\tif errParse != nil {\n\t\treturn 0, fmt.Errorf(\"weight must be an integer: %w\", errParse)\n\t}\n\treturn Normalize(weight)\n}\n\n// ParseValue parses a JSON-compatible auth-file metadata value.\nfunc ParseValue(value any) (int64, error) {\n\tswitch typed := value.(type) {\n\tcase int:\n\t\treturn Normalize(int64(typed))\n\tcase int8:\n\t\treturn Normalize(int64(typed))\n\tcase int16:\n\t\treturn Normalize(int64(typed))\n\tcase int32:\n\t\treturn Normalize(int64(typed))\n\tcase int64:\n\t\treturn Normalize(typed)\n\tcase uint:","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/credentialweight/weight.go#L21-L57","documentation":"Thrown by credentialweight.ParseString when a scheduler-attribute weight string cannot be parsed as a base-10 64-bit integer. Empty/whitespace-only strings are fine (they yield the Default of 1); only malformed numeric text fails.","triggerScenarios":"ParseString called with values like \"1.5\", \"1e3\", \"0x10\", \"1,000\", \"heavy\", or \"2 3\". Typically the value originates from an auth-file metadata attribute or scheduler attribute map.","commonSituations":"Hand-editing auth JSON files and writing a float (\"weight\": \"0.5\" as a string), including thousands separators or units, or trailing whitespace inside quotes.","solutions":["Use a plain decimal integer string such as \"10\" (or empty string / omit for default weight 1)","Remove decimal points, exponent notation, separators and units from the value","If floats must be supported at your layer, round to int first, then format with strconv.FormatInt"],"exampleFix":"// before\nw, err := credentialweight.ParseString(\"2.5\") // error\n\n// after\nw, err := credentialweight.ParseString(\"3\")","handlingStrategy":"validation","validationCode":"var intRe = regexp.MustCompile(`^-?\\d+$`)\n\nfunc validWeightString(s string) bool {\n    t := strings.TrimSpace(s)\n    return t == \"\" || intRe.MatchString(t)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only write plain decimal integers (\"10\") or empty strings into weight attributes","Never store floats as strings in auth metadata; round first","Trim and regex-check user-supplied weight strings at the input boundary"],"tags":["validation","parsing","go","credentialweight"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}