{"record":{"id":"4fff2838abcf1af4","repo":"gastownhall/beads","slug":"failed-to-parse-jsonl-line-w","errorCode":null,"errorMessage":"failed to parse JSONL line: %w","messagePattern":"failed to parse JSONL line: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/import.go","lineNumber":255,"sourceCode":"// reader): the optional _schema header and tombstones are skipped, and the\n// \"wisp_plane\" boolean is honored as the explicit wisps-plane marker (and\n// the legacy \"wisp\" alias for \"ephemeral\") via applyImportWispPlane.\nfunc parseImportRecords(r io.Reader) ([]*types.Issue, []memoryRecord, error) {\n\tscanner := bufio.NewScanner(r)\n\tscanner.Buffer(make([]byte, 0, 1024*1024), 64*1024*1024)\n\n\tvar issues []*types.Issue\n\tvar memories []memoryRecord\n\n\tfor scanner.Scan() {\n\t\tline := scanner.Text()\n\t\tif line == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar peek map[string]json.RawMessage\n\t\tif err := json.Unmarshal([]byte(line), &peek); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse JSONL line: %w\", err)\n\t\t}\n\n\t\t// Skip the optional beads-jsonl header record (§J1.3). A canonical\n\t\t// export may prepend a provenance line, e.g.\n\t\t// {\"_schema\":\"beads-jsonl/1\",\"_dolt_branch\":\"main\",\"_sort\":\"stable-v1\"}.\n\t\t// It carries no _type and no issue fields; without this guard it falls\n\t\t// through to the issue path, unmarshals into an empty Issue, and aborts\n\t\t// the whole import with \"title is required\". parseJSONLFile (the\n\t\t// bootstrap reader) has always skipped it; this loop — the one `bd\n\t\t// import` and `bd import -` run through — did not.\n\t\tif _, isHeader := peek[\"_schema\"]; isHeader {\n\t\t\tcontinue\n\t\t}\n\n\t\tif rawType, ok := peek[\"_type\"]; ok {\n\t\t\tvar typeStr string\n\t\t\tif err := json.Unmarshal(rawType, &typeStr); err == nil && typeStr == \"memory\" {\n\t\t\t\tvar mem memoryRecord","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/import.go#L237-L273","documentation":"A line of the JSONL stream fed to `bd import` is not valid JSON, so the pre-parse peek (json.Unmarshal into a generic map) fails before record-type dispatch. The wrapped underlying encoding/json error names the exact syntax problem and byte offset.","triggerScenarios":"`bd import file.jsonl` or `bd import -` where a line contains truncated JSON (e.g. a cut-off pipe transfer), stray prose/comment text, concatenated objects on one line, or invalid characters like a lone BOM.","commonSituations":"Editing an exported .jsonl by hand and breaking a line; piping output of another tool that adds banners; partial file download; Windows CRLF edge cases or copy-paste artifacts.","solutions":["Open the file at the reported line/offset and fix or remove the malformed JSON line","Re-export cleanly with `bd export -o file.jsonl` instead of hand-editing","If piping, check the upstream command for extra non-JSON output and redirect it to stderr","Validate the stream first: `while read -r l; do echo \"$l\" | jq empty || echo \"bad: $l\"; done < file.jsonl`"],"exampleFix":"// before (truncated line)\n{\"id\":\"bd-1\",\"title\":\"Fix\n// after\n{\"id\":\"bd-1\",\"title\":\"Fix login bug\",\"status\":\"open\"}","handlingStrategy":"validation","validationCode":"jq -c empty file.jsonl || echo 'invalid JSONL'   # or:\nawk '{print NR\": \"$0}' file.jsonl | while IFS= read -r l; do echo \"$l\" | jq empty >/dev/null || echo bad; done","typeGuard":null,"tryCatchPattern":"if ! bd import data.jsonl 2>err.log; then\n  grep 'failed to parse JSONL line' err.log   # locate offending line/offset\nfi","preventionTips":["Never hand-edit exported .jsonl; re-export with bd export instead","Validate JSONL with jq before every import","Strip tool banners when piping: producer output must be pure JSONL on stdout","Use LF line endings and remove BOM from generated files"],"tags":["json","parsing","cli"],"backgroundTag":"invalid-jsonl","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}