gastownhall/beads · error
read existing export: %w
Error message
read existing export: %w
What it means
rewriteExportFile loads the existing JSONL via loadExistingIssueLines before applying upserts/removals atomically. If reading the current export fails, the rewrite aborts with this wrapped error so the incremental export never clobbers a file it could not read — protecting against silent data loss.
Source
Thrown at cmd/bd/export_auto.go:1183
}
}
for _, s := range b {
if !seen[s] {
seen[s] = true
out = append(out, s)
}
}
return out
}
// rewriteExportFile applies a set of upserts and removals to an existing
// JSONL export and writes the result atomically. upsertOrder preserves
// append order for brand-new issue IDs; previously-present IDs keep their
// original file position even when their bodies are replaced.
func rewriteExportFile(path string, upserts map[string][]byte, removed map[string]bool, upsertOrder []string) (issueCount, memoryCount int, err error) {
lines, err := loadExistingIssueLines(path)
if err != nil {
return 0, 0, fmt.Errorf("read existing export: %w", err)
}
// Apply upserts: replace-in-place for known IDs, append (in input
// order) for brand-new IDs. This keeps stable ordering across runs
// instead of scrambling the file on every change.
for _, id := range upsertOrder {
line, ok := upserts[id]
if !ok {
continue
}
lines.set(id, line)
}
for id := range removed {
lines.remove(id)
}
w, err := atomicfile.Create(path, 0o644)View on GitHub (pinned to 71377f2769)
Solutions
- Regenerate the file with an explicit full export: `bd export -o .beads/issues.jsonl`, then retry `bd sync`
- Restore the file from git history if it was deleted or corrupted
- Fix filesystem-level issues (permissions, disk space) reported in the wrapped error
Example fix
// before // read existing export: open .beads/issues.jsonl: no such file or directory // after bd export -o .beads/issues.jsonl bd sync
Defensive patterns
Strategy: fallback
Validate before calling
// Verify the export file exists and is readable before incremental sync
if f, err := os.Open(".beads/issues.jsonl"); err != nil {
fmt.Println("export file missing/unreadable; do a full export")
} else {
f.Close()
} Try / catch
err := sync()
if err != nil && strings.Contains(err.Error(), "read existing export") {
// Fall back: regenerate the file with an explicit full export
runCmd("bd", "export", "-o", ".beads/issues.jsonl")
err = sync()
} Prevention
- Don't delete or move .beads/issues.jsonl while bd is running
- Restore the file from git before syncing after manual surgery on it
- Watch disk space on repos with large issue histories
- Prefer bd commands over manual edits for changing the JSONL
When it happens
Trigger: tryIncrementalExport calls rewriteExportFile, which calls loadExistingExportFile/loadExistingIssueLines(path) and gets a read/open/decode error — missing directory, permission denied, or malformed file when the reader rejects it.
Common situations: .beads/issues.jsonl deleted or moved after the incremental path decided to use it; permission changes; disk full during read; corrupted JSONL from a crashed prior write.
Related errors
- open batch file: %w
- open dependency file: %w
- read dependency file: %w
- failed to initialize database: %w
- failed to load issues: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/25bc3811e530d353.
Report an issue: GitHub.