router-for-me/CLIProxyAPI · warning
weight must be an integer
Error message
weight must be an integer
What it means
parseCredentialWeightPatch could not JSON-decode the weight value into an int — the raw bytes are valid JSON but not an integer literal: a string ("3"), a float (2.5), a bool, an array/object, or trailing content after the number. Weights must be whole numbers and are further constrained by config.ValidateCredentialWeight.
Source
Thrown at internal/api/handlers/management/config_lists.go:23
"encoding/json"
"fmt"
"strings"
"github.com/gin-gonic/gin"
"github.com/router-for-me/CLIProxyAPI/v7/internal/config"
)
func parseCredentialWeightPatch(raw json.RawMessage) (*int, error) {
if len(raw) == 0 {
return nil, fmt.Errorf("weight is missing")
}
if bytes.Equal(bytes.TrimSpace(raw), []byte("null")) {
return nil, nil
}
var weight int
decoder := json.NewDecoder(bytes.NewReader(raw))
if errDecode := decoder.Decode(&weight); errDecode != nil {
return nil, fmt.Errorf("weight must be an integer")
}
if errValidate := config.ValidateCredentialWeight(&weight); errValidate != nil {
return nil, errValidate
}
return &weight, nil
}
func rejectInvalidCredentialWeight(c *gin.Context, field string, weight *int) bool {
if errValidate := config.ValidateCredentialWeight(weight); errValidate != nil {
c.JSON(400, gin.H{"error": fmt.Sprintf("%s: %v", field, errValidate)})
return true
}
return false
}
// Generic helpers for list[string]
func (h *Handler) putStringList(c *gin.Context, set func([]string), after func()) {
data, err := c.GetRawData()View on GitHub (pinned to 78f0c4079e)
Solutions
- Send a plain JSON integer for weight (no quotes, no decimals)
- Validate client-side before the request that weight is an integer within the configured bounds
- If a fractional or quoted value is legitimate in your UX, convert to int before sending
- Check config.ValidateCredentialWeight's bounds so the follow-up validation does not reject the value
Example fix
// before
{"weight": "3"}
// after
{"weight": 3} Defensive patterns
Strategy: type-guard
Validate before calling
var w float64
if err := json.Unmarshal(raw, &w); err != nil || w != math.Trunc(w) {
return errors.New("weight must be an integer")
} Type guard
func isJSONInt(raw json.RawMessage) bool {
var w int
dec := json.NewDecoder(bytes.NewReader(raw))
return dec.Decode(&w) == nil && dec.More() == false
} Try / catch
if err := decoder.Decode(&weight); err != nil {
c.JSON(400, gin.H{"error": "weight must be a JSON integer, e.g. 3"})
} Prevention
- Type weight as an integer number in client schemas
- Validate payload shape with JSON Schema before sending
- Never quote numeric fields
When it happens
Trigger: PATCHing a credential's weight with 2.5, "3", true, or {"value":3}; clients sending weights as strings because their config layer typed them as text.
Common situations: Frontend forms binding weight to a text input; loosely typed (any) payloads in TypeScript clients; JSON generators quoting numbers; locale formatting inserting decimal separators.
Related errors
- weight is missing
- invalid request body
- invalid field path: %s
- home models payload has no sections
- weight must be an integer
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/72a11fe3ed9aea21.
Report an issue: GitHub.