router-for-me/CLIProxyAPI · error
weight must be an integer: %w
Error message
weight must be an integer: %w
What it means
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.
Source
Thrown at internal/credentialweight/weight.go:39
func Normalize(weight int64) (int64, error) {
if weight <= 0 {
return 0, nil
}
if weight > Max {
return 0, fmt.Errorf("weight must not exceed %d", Max)
}
return weight, nil
}
// ParseString parses a scheduler attribute. An empty value uses the default weight.
func ParseString(raw string) (int64, error) {
raw = strings.TrimSpace(raw)
if raw == "" {
return Default, nil
}
weight, errParse := strconv.ParseInt(raw, 10, 64)
if errParse != nil {
return 0, fmt.Errorf("weight must be an integer: %w", errParse)
}
return Normalize(weight)
}
// ParseValue parses a JSON-compatible auth-file metadata value.
func ParseValue(value any) (int64, error) {
switch typed := value.(type) {
case int:
return Normalize(int64(typed))
case int8:
return Normalize(int64(typed))
case int16:
return Normalize(int64(typed))
case int32:
return Normalize(int64(typed))
case int64:
return Normalize(typed)
case uint:View on GitHub (pinned to 78f0c4079e)
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
Example fix
// before
w, err := credentialweight.ParseString("2.5") // error
// after
w, err := credentialweight.ParseString("3") Defensive patterns
Strategy: validation
Validate before calling
var intRe = regexp.MustCompile(`^-?\d+$`)
func validWeightString(s string) bool {
t := strings.TrimSpace(s)
return t == "" || intRe.MatchString(t)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- weight must be an integer
- weight must not exceed %d
- invalid auth file name
- auth file name must end with .json
- json is required
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/31baaf1d5963cf87.
Report an issue: GitHub.