JuliusBrussee/caveman · error

caveman-jsonl line

Error message

caveman-jsonl line %d: %w

What it means

The caveman-jsonl importer parses one JSON span per line; json.Unmarshal failed for the line at the given 1-based index, so parseCavemanJSONL aborts with the line number and underlying decode error wrapped via %w.

Solutions

  1. Open the file at the reported line number and fix or remove the malformed line.
  2. Validate the whole file per-line with jq (jq -c . file.jsonl) to find all bad lines before re-importing.
  3. Ensure the producer writes one compact JSON object per line.
  4. Check field types match the Span schema (numeric timestamps, string ids).
Defensive patterns

Strategy: validation

Validate before calling

func validateJSONL(data []byte) error {
	for i, line := range bytes.Split(data, []byte("\n")) {
		line = bytes.TrimSpace(line)
		if len(line) == 0 {
			continue
		}
		var v map[string]any
		if err := json.Unmarshal(line, &v); err != nil {
			return fmt.Errorf("line %d: %w", i+1, err)
		}
	}
	return nil
}

Try / catch

spans, err := importers.Parse(data)
if err != nil {
	if strings.Contains(err.Error(), "caveman-jsonl line ") {
		return fmt.Errorf("malformed span in input: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Parse() on a .jsonl file where a line is malformed JSON: trailing commas, single quotes, truncated line, non-JSON garbage, or JSON whose field types mismatch the Span struct (e.g. timestamp as string where a number is expected).

Common situations: Files partially written during a crash; pretty-printed multi-line JSON instead of JSONL; concatenating objects where embedded newlines split a record; hand-edited spans.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/a0d6b3cc72ff1c93. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/importers/caveman_jsonl.go:22

	"bytes"
	"encoding/json"
	"fmt"
)

// parseCavemanJSONL parses one JSON span per line. Each line is already close
// to the Span shape (the same column names), so it unmarshals directly into a
// Span and then has the authenticated scope stamped over it. Blank lines are
// skipped. A malformed line aborts the whole import (no partial silent ingest).
func parseCavemanJSONL(data []byte, opts Options) ([]Span, error) {
	var rows []Span
	for i, line := range bytes.Split(data, []byte("\n")) {
		line = bytes.TrimSpace(line)
		if len(line) == 0 {
			continue
		}
		var sp Span
		if err := json.Unmarshal(line, &sp); err != nil {
			return nil, fmt.Errorf("caveman-jsonl line %d: %w", i+1, err)
		}
		applyScope(&sp, opts)
		rows = append(rows, sp)
	}
	return rows, nil
}

View on GitHub (pinned to 3ee70a1026)