{"record":{"id":"d92924be29b6a141","repo":"cayleygraph/cayley","slug":"could-not-write-history-to-q-v","errorCode":null,"errorMessage":"could not write history to %q: %v","messagePattern":"could not write history to %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/repl/repl.go","lineNumber":280,"sourceCode":"\n\tf, err := os.Open(path)\n\tif err != nil {\n\t\treturn term, err\n\t}\n\tdefer f.Close()\n\t_, err = term.ReadHistory(f)\n\treturn term, err\n}\n\nfunc persist(term *liner.State, path string) error {\n\tf, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not open %q to append history: %v\", path, err)\n\t}\n\tdefer f.Close()\n\t_, err = term.WriteHistory(f)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not write history to %q: %v\", path, err)\n\t}\n\treturn term.Close()\n}\n","sourceCodeStart":262,"sourceCodeEnd":284,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/internal/repl/repl.go#L262-L284","documentation":"This error is returned by the persist function in internal/repl/repl.go when the liner terminal fails to write the accumulated readline history to the history file on disk. The history file was opened successfully (OS-level open succeeded), but term.WriteHistory(f) failed while serializing or writing the history entries. It wraps the underlying liner error with the file path for context.","triggerScenarios":"Calling persist(term, path) where os.OpenFile succeeded but liner's WriteHistory fails — e.g. the file descriptor becomes invalid mid-write, the disk fills up, or the liner state is corrupted/closed before the write. It is invoked during REPL shutdown/cleanup paths from Repl and an anonymous cleanup goroutine.","commonSituations":"Disk-full or quota-exceeded while exiting a REPL session; history file on a network mount that dropped; another process truncating or locking the history file concurrently; file system became read-only after open.","solutions":["Check the wrapped %v error for the underlying cause (ENOSPC, EIO, EBADF) and free disk space or fix the filesystem","Verify the history file path is on a writable, available filesystem","Check that no other process holds a conflicting lock on the history file","Retry persisting, or fall back to skipping history persistence so the REPL still exits cleanly"],"exampleFix":"// before\n_, err = term.WriteHistory(f)\nif err != nil {\n    return fmt.Errorf(\"could not write history to %q: %v\", path, err)\n}\n// after\n_, err = term.WriteHistory(f)\nif err != nil {\n    log.Printf(\"warning: history not saved to %q: %v\", path, err)\n    return nil // don't fail REPL shutdown over history persistence\n}","handlingStrategy":"try-catch","validationCode":"f, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)\nif err != nil { return err }\nf.Close()\n// disk space check (unix)\n// syscall.Statfs(path, &st); if st.Bavail*uint64(st.Bsize) < minFree { ... }","typeGuard":null,"tryCatchPattern":"if err := persist(term, historyPath); err != nil {\n    if strings.Contains(err.Error(), \"could not write history\") {\n        log.Printf(\"history not saved: %v\", err) // degrade gracefully\n    } else {\n        return err\n    }\n}","preventionTips":["Keep the history file on local writable storage, not network mounts","Check available disk space before long REPL sessions","Don't close the liner term before persist runs","Treat history persistence as best-effort and never let it block shutdown"],"tags":["filesystem","io","repl","history"],"backgroundTag":"file-write-failed","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}