{"record":{"id":"56cce490d13db7ef","repo":"JuliusBrussee/caveman","slug":"cachebench-observation-line-d-trailing-json","errorCode":null,"errorMessage":"cachebench: observation line %d: trailing JSON","messagePattern":"cachebench: observation line (.+?): trailing JSON","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/observed.go","lineNumber":126,"sourceCode":"\t\traw := bytes.TrimSpace(scanner.Bytes())\n\t\tif len(raw) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif len(records) >= limits.MaxRecords {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observations exceed record limit %d\", limits.MaxRecords)\n\t\t}\n\t\tif !validUniqueJSONObject(raw) {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: duplicate or invalid JSON\", line)\n\t\t}\n\t\tdecoder := json.NewDecoder(bytes.NewReader(raw))\n\t\tdecoder.DisallowUnknownFields()\n\t\tvar record ObservationRecord\n\t\tif err := decoder.Decode(&record); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: %w\", line, err)\n\t\t}\n\t\tvar trailing any\n\t\tif err := decoder.Decode(&trailing); err != io.EOF {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: trailing JSON\", line)\n\t\t}\n\t\tif record.Schema != ObservationSchema {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: schema %q\", line, record.Schema)\n\t\t}\n\t\tif strings.TrimSpace(record.RequestID) == \"\" || seen[record.RequestID] {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: empty or duplicate request_id\", line)\n\t\t}\n\t\tseen[record.RequestID] = true\n\t\trecord.Usage = append(json.RawMessage(nil), record.Usage...)\n\t\trecords = append(records, record)\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"cachebench: read observations: %w\", err)\n\t}\n\tif len(records) == 0 {\n\t\treturn nil, errors.New(\"cachebench: no observation records\")\n\t}\n\tif err := validateObservationRecords(records); err != nil {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/cachebench/observed.go#L108-L144","documentation":"After decoding one ObservationRecord from a line, a second decode must return io.EOF; anything else means extra JSON follows the object on the same line (e.g. two objects or stray tokens). One line must contain exactly one JSON object.","triggerScenarios":"An observation line like '{...}{...}' or '{...} trailing' — the first object decodes, then the follow-up decode does not yield io.EOF and the line number is reported.","commonSituations":"Concatenation scripts joining JSON objects without newlines; a writer missing a trailing newline so two records land on one line; shell heredocs collapsing lines.","solutions":["Ensure the observation writer emits exactly one JSON object per line with '\\n' separators.","Re-split any concatenated file so each object is on its own line.","Check for missing final newlines when files are appended in place."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func oneObjectPerLine(line []byte) error {\n\tdec := json.NewDecoder(bytes.NewReader(line))\n\tvar rec ObservationRecord\n\tif err := dec.Decode(&rec); err != nil {\n\t\treturn err\n\t}\n\tvar trailing any\n\tif err := dec.Decode(&trailing); err != io.EOF {\n\t\treturn fmt.Errorf(\"trailing JSON\")\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always terminate records with '\\n' when writing JSONL.","When concatenating files, ensure the source ends with a newline first.","Never emit multiple objects per line in observation writers."],"tags":["go","json","jsonl","formatting"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}