{"record":{"id":"eda810bba39c2d8a","repo":"gastownhall/beads","slug":"failed-to-parse-issue-from-jsonl-w-eda810","errorCode":null,"errorMessage":"failed to parse issue from JSONL: %w","messagePattern":"failed to parse issue from JSONL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/import_shared.go","lineNumber":1041,"sourceCode":"\t\t// Check if this is a memory record\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\n\t\t\t\tif err := json.Unmarshal([]byte(line), &mem); err != nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse memory record: %w\", err)\n\t\t\t\t}\n\t\t\t\tif mem.Key != \"\" && mem.Value != \"\" {\n\t\t\t\t\tconfigEntries[kvPrefix+memoryPrefix+mem.Key] = mem.Value\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\t// Regular issue record\n\t\tvar issue types.Issue\n\t\tif err := json.Unmarshal([]byte(line), &issue); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to parse issue from JSONL: %w\", err)\n\t\t}\n\t\t// Skip tombstone entries: these are deleted issues exported by older\n\t\t// versions (pre-v0.50) with status \"tombstone\" and deleted_at set.\n\t\t// They are not valid for re-import since \"tombstone\" is not a real status.\n\t\tif issue.Status == \"tombstone\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tapplyImportWispPlane(peek, &issue)\n\n\t\tissue.SetDefaults()\n\t\tissues = append(issues, &issue)\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to scan JSONL: %w\", err)\n\t}\n\n\treturn issues, configEntries, nil","sourceCodeStart":1023,"sourceCodeEnd":1059,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/import_shared.go#L1023-L1059","documentation":"parseJSONLFile reads a beads JSONL export line by line. After skipping schema headers and memory records, each remaining line is unmarshaled into types.Issue; if the JSON does not decode into a valid Issue struct (malformed JSON, wrong types for fields, truncated line), the whole parse aborts with this wrapped error.","triggerScenarios":"Calling `bd init --from-jsonl`, `bd bootstrap`, or the auto-import path (maybeAutoImportJSONL / importFromLocalJSONLWithOpts) on a JSONL file where a line that is not a _schema header and not a _type:\"memory\" record fails json.Unmarshal into types.Issue — e.g. hand-edited lines, corrupted merges, or type mismatches (a string where a timestamp is expected).","commonSituations":"Git merge conflicts left half-resolved in .beads/issues.jsonl; an external script appended non-beads JSON to the export; a partial/truncated file written during a crash; an export from an incompatible bd version with shifted field types.","solutions":["Open the file and run each line through `jq -e .` (or `python -m json.tool`) to find the malformed line named in the wrapped %w error","Fix or delete the corrupt line (or re-resolve the git merge conflict), keeping one valid JSON object per line","If the file came from `bd export`, regenerate it with the same bd version instead of hand-editing","Check for version skew: re-export with the current `bd` binary rather than importing an old-format file"],"exampleFix":"// before (corrupt line in .beads/issues.jsonl)\n{\"id\":\"bd-1\",\"title\":\"fix\" \"priority\":1\n// after (valid single-line JSON object)\n{\"id\":\"bd-1\",\"title\":\"fix\",\"priority\":1}","handlingStrategy":"validation","validationCode":"// Validate the JSONL before import: one JSON object per line\nfor i, line := range strings.Split(string(data), \"\\n\") {\n    line = strings.TrimSpace(line)\n    if line == \"\" { continue }\n    var probe map[string]any\n    if err := json.Unmarshal([]byte(line), &probe); err != nil {\n        return fmt.Errorf(\"line %d is not valid JSON: %w\", i+1, err)\n    }\n}","typeGuard":"func isHeaderRecord(line string) bool {\n    var peek map[string]json.RawMessage\n    if json.Unmarshal([]byte(line), &peek) != nil { return false }\n    _, ok := peek[\"_schema\"]\n    return ok\n}","tryCatchPattern":"if _, _, err := parseJSONLFile(path); err != nil {\n    var parseErr *json.UnmarshalTypeError\n    if errors.As(err, &parseErr) {\n        log.Fatalf(\"malformed issue record (field %s): %v\", parseErr.Field, err)\n    }\n    return err\n}","preventionTips":["Never hand-edit issues.jsonl; regenerate with `bd export`","Resolve git merge conflicts in .beads/ files fully before running bd","Keep one JSON object per line; validate with jq after any external tooling touches the file","Use the same (current) bd version for export and import to avoid schema skew"],"tags":["jsonl","json-parsing","import","corrupt-file"],"backgroundTag":"jsonl-parse-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}