router-for-me/CLIProxyAPI · error

home models payload is empty

Error message

home models payload is empty

What it means

decodeHomeModels rejects its input when the raw payload byte slice is empty (len == 0). This function parses the JSON payload fetched from the home models source into model entries; an empty body means nothing was fetched or an upstream returned zero bytes.

Source

Thrown at internal/api/server_routes.go:970

		return msg
	}
	return "home models request failed"
}

func unmarshalHomeModelsTopLevel(raw []byte) (map[string]json.RawMessage, bool) {
	if len(raw) == 0 {
		return nil, false
	}
	var top map[string]json.RawMessage
	if errUnmarshal := json.Unmarshal(raw, &top); errUnmarshal != nil {
		return nil, false
	}
	return top, true
}

func decodeHomeModels(raw []byte) ([]homeModelEntry, error) {
	if len(raw) == 0 {
		return nil, fmt.Errorf("home models payload is empty")
	}

	var bySection map[string][]map[string]any
	if err := json.Unmarshal(raw, &bySection); err != nil {
		return nil, fmt.Errorf("parse home models payload: %w", err)
	}
	if len(bySection) == 0 {
		return nil, fmt.Errorf("home models payload has no sections")
	}

	seen := make(map[string]struct{})
	out := make([]homeModelEntry, 0, 256)
	for _, models := range bySection {
		for _, model := range models {
			id, _ := model["id"].(string)
			id = strings.TrimSpace(id)
			if id == "" {
				name, _ := model["name"].(string)

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Verify what the home models fetch actually returned (log status code and Content-Length before decoding)
  2. Treat an empty payload as a fetch failure and retry or fall back to the last known-good cached payload instead of decoding empty bytes
  3. If the upstream now legitimately returns empty, skip the decode path rather than treating it as a model list

Example fix

// before
raw, _ := fetchHomeModels(ctx)
entries, err := decodeHomeModels(raw)

// after
raw, errFetch := fetchHomeModels(ctx)
if errFetch != nil || len(raw) == 0 {
	return nil, fmt.Errorf("home models fetch returned no data: %w", errFetch)
}
entries, err := decodeHomeModels(raw)
Defensive patterns

Strategy: validation

Validate before calling

if len(raw) == 0 {
	return fmt.Errorf("home models fetch returned empty payload")
}
entries, err := decodeHomeModels(raw)

Try / catch

if _, err := decodeHomeModels(raw); err != nil {
	log.Warnf("home models decode failed: %v; keeping previous model list", err)
}

Prevention

When it happens

Trigger: The upstream home models endpoint returned HTTP 200 with an empty body; a fetch layer returned a nil/empty byte slice without an error; the cached payload was truncated to zero length.

Common situations: Upstream API change returning 204 instead of 200 with content; a caching layer storing an empty value on a failed fetch; network intermediary stripping the body.

Related errors


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