JuliusBrussee/caveman · error

cachebench: trace line

Error message

cachebench: trace line %d: %w

What it means

json.Decoder failed to decode trace line %d into a TraceRecord (with DisallowUnknownFields), meaning the line is malformed, has a type mismatch, or contains an unknown field. The wrapped decode error gives specifics.

Solutions

  1. Align the line with the current TraceRecord schema
  2. Remove unknown fields or update the reader for the new schema
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cacheengine/cachebench/trace.go:306 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/21cc3686deacc7e2. Report an issue: GitHub.

Appendix: source

Thrown at cacheengine/cachebench/trace.go:306

	scanner.Buffer(make([]byte, initial), limits.MaxLineBytes)
	seen := map[string]bool{}
	var records []TraceRecord
	for line := 1; scanner.Scan(); line++ {
		raw := bytes.TrimSpace(scanner.Bytes())
		if len(raw) == 0 {
			continue
		}
		if len(records) >= limits.MaxRecords {
			return nil, fmt.Errorf("cachebench: trace exceeds record limit %d", limits.MaxRecords)
		}
		if !validUniqueJSONObject(raw) {
			return nil, fmt.Errorf("cachebench: trace line %d: duplicate or invalid JSON", line)
		}
		decoder := json.NewDecoder(bytes.NewReader(raw))
		decoder.DisallowUnknownFields()
		var record TraceRecord
		if err := decoder.Decode(&record); err != nil {
			return nil, fmt.Errorf("cachebench: trace line %d: %w", line, err)
		}
		var trailing any
		if err := decoder.Decode(&trailing); err != io.EOF {
			return nil, fmt.Errorf("cachebench: trace line %d: trailing JSON", line)
		}
		if record.Schema != TraceSchema && record.Schema != TraceSchemaV2 && record.Schema != TraceSchemaV1 || !validBoundedText(record.RequestID, 512, false) || seen[record.RequestID] {
			return nil, fmt.Errorf("cachebench: trace line %d: invalid schema or request_id", line)
		}
		if _, err := time.Parse(time.RFC3339Nano, record.At); err != nil || !validTraceIdentity(record) || record.PrefixTokens < 0 {
			return nil, fmt.Errorf("cachebench: trace line %d: incomplete request identity", line)
		}
		if len(record.Body) > limits.MaxBodyBytes || !json.Valid(record.Body) || record.BodySHA256 == "" || record.BodySHA256 != bodyDigest(record.Body) {
			return nil, fmt.Errorf("cachebench: trace line %d: invalid body or digest", line)
		}
		if record.StableSegmentCount < 0 || record.StableSegmentCount > len(record.Prefix) || !validPrefix(record.Prefix) {
			return nil, fmt.Errorf("cachebench: trace line %d: invalid prefix", line)
		}
		if record.Schema == TraceSchema || record.Schema == TraceSchemaV2 {

View on GitHub (pinned to 766dce6b13)