{"record":{"id":"a0d6b3cc72ff1c93","repo":"JuliusBrussee/caveman","slug":"caveman-jsonl-line-d-w","errorCode":null,"errorMessage":"caveman-jsonl line %d: %w","messagePattern":"caveman-jsonl line (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/importers/caveman_jsonl.go","lineNumber":22,"sourceCode":"\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n)\n\n// parseCavemanJSONL parses one JSON span per line. Each line is already close\n// to the Span shape (the same column names), so it unmarshals directly into a\n// Span and then has the authenticated scope stamped over it. Blank lines are\n// skipped. A malformed line aborts the whole import (no partial silent ingest).\nfunc parseCavemanJSONL(data []byte, opts Options) ([]Span, error) {\n\tvar rows []Span\n\tfor i, line := range bytes.Split(data, []byte(\"\\n\")) {\n\t\tline = bytes.TrimSpace(line)\n\t\tif len(line) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tvar sp Span\n\t\tif err := json.Unmarshal(line, &sp); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"caveman-jsonl line %d: %w\", i+1, err)\n\t\t}\n\t\tapplyScope(&sp, opts)\n\t\trows = append(rows, sp)\n\t}\n\treturn rows, nil\n}\n","sourceCodeStart":4,"sourceCodeEnd":29,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/importers/caveman_jsonl.go#L4-L29","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Open the file at the reported line number and fix or remove the malformed line.","Validate the whole file per-line with jq (jq -c . file.jsonl) to find all bad lines before re-importing.","Ensure the producer writes one compact JSON object per line.","Check field types match the Span schema (numeric timestamps, string ids)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func validateJSONL(data []byte) error {\n\tfor i, line := range bytes.Split(data, []byte(\"\\n\")) {\n\t\tline = bytes.TrimSpace(line)\n\t\tif len(line) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tvar v map[string]any\n\t\tif err := json.Unmarshal(line, &v); err != nil {\n\t\t\treturn fmt.Errorf(\"line %d: %w\", i+1, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"spans, err := importers.Parse(data)\nif err != nil {\n\tif strings.Contains(err.Error(), \"caveman-jsonl line \") {\n\t\treturn fmt.Errorf(\"malformed span in input: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Emit strict JSONL: one compact object per line, no pretty-printing.","Pre-validate with `jq -c . file.jsonl` before importing.","Ensure writers flush lines atomically to avoid truncated lines on crash.","Keep Span field types consistent (numbers as numbers, strings as strings)."],"tags":["jsonl","json","importer","parse"],"backgroundTag":"json-parse-error","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}