JuliusBrussee/caveman · error

cachebench: trailing JSON after Hugging Face rows object

Error message

cachebench: trailing JSON after Hugging Face rows object

What it means

Raised in readHFRows when decoding after the root object's '}' yields anything other than io.EOF. The parser demands exactly one JSON document; trailing bytes (second object, stray newline-delimited records, appended log lines) are rejected.

Solutions

  1. Feed only a single HF rows JSON object to the HFRows reader
  2. If you have newline-delimited records, switch to the LMCache JSONL format instead
  3. Trim trailing whitespace-only junk, but note any non-whitespace trailing content is a hard error
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at cacheengine/cachebench/corpus.go:292

			}
			row, err := validateCorpusWire(wire.Row, wire.RowIndex, limits)
			if err != nil {
				return nil, fmt.Errorf("cachebench: Hugging Face row %d: %w", wire.RowIndex, err)
			}
			if err := appendCorpusRow(&rows, sessions, &retainedBytes, row, limits); err != nil {
				return nil, fmt.Errorf("cachebench: Hugging Face row %d: %w", wire.RowIndex, err)
			}
		}
		if end, err := decoder.Token(); err != nil || end != json.Delim(']') {
			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")

View on GitHub (pinned to 766dce6b13)