{"record":{"id":"f04344fe19b8b04f","repo":"gastownhall/beads","slug":"failed-to-write-issue-s-w","errorCode":null,"errorMessage":"failed to write issue %s: %w","messagePattern":"failed to write issue (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/detect_pollution.go","lineNumber":116,"sourceCode":"\nfunc backupPollutedIssues(polluted []pollutionResult, path string) error {\n\t// Create backup file\n\t// nolint:gosec // G304: path is provided by user as explicit backup location\n\tfile, err := os.Create(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create backup file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\t// Write each issue as JSONL\n\tfor _, p := range polluted {\n\t\tdata, err := json.Marshal(p.issue)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to marshal issue %s: %w\", p.issue.ID, err)\n\t\t}\n\n\t\tif _, err := file.WriteString(string(data) + \"\\n\"); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write issue %s: %w\", p.issue.ID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":98,"sourceCodeEnd":122,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/detect_pollution.go#L98-L122","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"null","handlingStrategy":"fallback","validationCode":"if st, err := os.Stat(filepath.Dir(backupPath)); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"backup target unavailable\")\n}\n// check free space\nif us, err := diskusage(filepath.Dir(backupPath)); err == nil && us.Free < minRequired {\n    return fmt.Errorf(\"insufficient disk space for backup\")\n}","typeGuard":null,"tryCatchPattern":"if err := backupPollutedIssues(polluted, path); err != nil {\n    alt := filepath.Join(os.TempDir(), \"beads-backup.jsonl\")\n    log.Printf(\"primary backup failed (%v); retrying at %s\", err, alt)\n    return backupPollutedIssues(polluted, alt)\n}","preventionTips":["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."],"tags":["go","filesystem","io","backup"],"backgroundTag":"file-write-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}