gastownhall/beads · error
failed to write issue %s: %w
Error message
failed to write issue %s: %w
What it means
After marshaling, backupPollutedIssues writes each JSONL line to the backup file with file.WriteString. If the write fails — disk full, I/O error, file closed, or device error — this wrapped error naming the issue ID is returned, aborting the remainder of the backup.
Source
Thrown at cmd/bd/detect_pollution.go:116
func backupPollutedIssues(polluted []pollutionResult, path string) error {
// Create backup file
// nolint:gosec // G304: path is provided by user as explicit backup location
file, err := os.Create(path)
if err != nil {
return fmt.Errorf("failed to create backup file: %w", err)
}
defer file.Close()
// Write each issue as JSONL
for _, p := range polluted {
data, err := json.Marshal(p.issue)
if err != nil {
return fmt.Errorf("failed to marshal issue %s: %w", p.issue.ID, err)
}
if _, err := file.WriteString(string(data) + "\n"); err != nil {
return fmt.Errorf("failed to write issue %s: %w", p.issue.ID, err)
}
}
return nil
}
View on GitHub (pinned to 71377f2769)
Solutions
- Check free disk space (df -h) and quota, then free space or choose another volume.
- Retry the backup after confirming the target filesystem is writable and healthy.
- Back up to a local, reliable path instead of network/removable storage.
- Verify partial backup contents and re-run; the file is recreated by os.Create on retry.
Example fix
null
Defensive patterns
Strategy: fallback
Validate before calling
if st, err := os.Stat(filepath.Dir(backupPath)); err != nil || !st.IsDir() {
return fmt.Errorf("backup target unavailable")
}
// check free space
if us, err := diskusage(filepath.Dir(backupPath)); err == nil && us.Free < minRequired {
return fmt.Errorf("insufficient disk space for backup")
} Try / catch
if err := backupPollutedIssues(polluted, path); err != nil {
alt := filepath.Join(os.TempDir(), "beads-backup.jsonl")
log.Printf("primary backup failed (%v); retrying at %s", err, alt)
return backupPollutedIssues(polluted, alt)
} Prevention
- Check free disk space (df -h) before large backup operations.
- Back up to local disks rather than network or removable storage.
- Retry the backup; os.Create truncates so partial files are rewritten cleanly.
- Set up disk-space monitoring on machines running scheduled bd jobs.
When it happens
Trigger: os.Create and json.Marshal succeeded, but file.WriteString fails mid-loop: ENOSPC (disk full), I/O error on the filesystem, or the underlying file handle became invalid.
Common situations: Disk quota exceeded or full volume during backup; network-attached storage disconnected mid-write; backing up to a failing/removable device; permission revocation mid-operation.
Related errors
- failed to read backup state: %w
- failed to create backup dir in git-repo: %w
- failed to create backup directory: %w
- failed to write temp file: %w
- failed to sync temp file: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/f04344fe19b8b04f.
Report an issue: GitHub.