JuliusBrussee/caveman · error

trailing JSON

Error message

trailing JSON

What it means

Generic sentinel from decodeOneJSON: after successfully decoding one JSON value from the raw bytes, a second decode did not return io.EOF. The blob holds more than one JSON document (e.g. two concatenated objects), which strict single-value decoding forbids.

Solutions

  1. Split concatenated JSON values in the row before passing it in
  2. Strip anything after the first complete JSON value (comments, trailing commas, second document)
  3. If multi-document input is expected, restructure it as JSONL and use the line-based reader
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/corpus.go:310 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/6b10c2793a5931dc. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/corpus.go:310

		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)
	}
	if len(wire.Input) == 0 || !json.Valid(wire.Input) {
		return CorpusRow{}, errors.New("input must be valid non-empty message array")
	}
	if len(wire.SessionID)+len(wire.Model)+len(wire.Input) > limits.MaxRowBytes {
		return CorpusRow{}, fmt.Errorf("row exceeds byte limit %d", limits.MaxRowBytes)
	}
	var messages []CorpusMessage

View on GitHub (pinned to 766dce6b13)