JuliusBrussee/caveman · error

duplicate or invalid JSON

Error message

duplicate or invalid JSON

What it means

Generic sentinel from decodeOneJSON: the raw row bytes failed validUniqueJSONObject, meaning the blob is not a valid JSON object or contains duplicate top-level (or nested, per the checker) keys. Callers wrap it with context (e.g. 'decode Hugging Face row: ...'), so the fault is in the individual row's raw bytes, not the enclosing stream.

Solutions

  1. Validate the offending row blob independently (e.g. jq) to see whether it is malformed or has duplicate keys
  2. Remove duplicate JSON keys — later keys silently overriding earlier ones are rejected here by design
  3. Regenerate the row from the source dataset instead of patching it by hand
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/corpus.go:302 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/a4ea1aab600bfed5. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/corpus.go:302

			return nil, errors.New("cachebench: malformed Hugging Face rows array")
		}
	}
	if end, err := decoder.Token(); err != nil || end != json.Delim('}') {
		return nil, errors.New("cachebench: malformed Hugging Face rows object")
	}
	var trailing any
	if err := decoder.Decode(&trailing); err != io.EOF {
		return nil, errors.New("cachebench: trailing JSON after Hugging Face rows object")
	}
	if !foundRows {
		return nil, errors.New("cachebench: Hugging Face response has no rows field")
	}
	return rows, nil
}

func decodeOneJSON(raw []byte, destination any) error {
	if !validUniqueJSONObject(raw) {
		return errors.New("duplicate or invalid JSON")
	}
	decoder := json.NewDecoder(bytes.NewReader(raw))
	if err := decoder.Decode(destination); err != nil {
		return err
	}
	var trailing any
	if err := decoder.Decode(&trailing); err != io.EOF {
		return errors.New("trailing JSON")
	}
	return nil
}

func validateCorpusWire(wire lmcacheRowWire, index int, limits CorpusLimits) (CorpusRow, error) {
	if !validBoundedText(wire.SessionID, 2048, false) || !validBoundedText(wire.Model, 512, false) {
		return CorpusRow{}, errors.New("session_id and model required")
	}
	if wire.OutputLength < 0 || math.IsNaN(wire.PreGap) || math.IsInf(wire.PreGap, 0) || wire.PreGap < 0 || wire.PreGap > maxCorpusGapSeconds {
		return CorpusRow{}, fmt.Errorf("output_length must be non-negative and pre_gap must be within 0..%d seconds", maxCorpusGapSeconds)

View on GitHub (pinned to 766dce6b13)