router-for-me/CLIProxyAPI · warning

weight is missing

Error message

weight is missing

What it means

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.

Source

Thrown at internal/api/handlers/management/config_lists.go:15

package management

import (
	"bytes"
	"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)})

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Send a complete body: {"weight": 3} to set, {"weight": null} to clear, or omit the key entirely
  2. Validate the JSON before sending (most HTTP clients reject {"weight":} at parse time)
  3. If writing calling code, only include weight in the patch map when a value exists
  4. Retry with the corrected payload

Example fix

# before
curl -X PATCH .../gemini-key/0 -d '{"weight":}'
# after
curl -X PATCH .../gemini-key/0 -d '{"weight": 3}'
Defensive patterns

Strategy: validation

Validate before calling

if len(rawWeight) == 0 { /* omit weight from the patch body instead of sending empty */ }

Type guard

func isSendableWeight(raw json.RawMessage) bool { return len(raw) > 0 }

Prevention

When it happens

Trigger: 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.

Common situations: Client libraries serializing undefined or absent values into empty raw bytes; hand-crafted curl bodies with malformed JSON; an intermediary proxy stripping the value.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/6b4c482b579cbf91. Report an issue: GitHub.