{"record":{"id":"1a924c7c0ed96581","repo":"wavetermdev/waveterm","slug":"failed-to-write-backup-file-w","errorCode":null,"errorMessage":"failed to write backup file: %w","messagePattern":"failed to write backup file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/filebackup/filebackup.go","lineNumber":65,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"failed to generate UUID: %w\", err)\n\t}\n\tuuidStr := uuidV7.String()\n\n\tnow := time.Now()\n\tdateStr := now.Format(\"2006-01-02\")\n\n\tbackupDir := filepath.Join(wavebase.GetWaveCachesDir(), \"waveai-backups\", dateStr)\n\terr = os.MkdirAll(backupDir, 0700)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create backup directory: %w\", err)\n\t}\n\n\tbackupName := fmt.Sprintf(\"%s.%s.%s.bak\", basename, dirHash8, uuidStr)\n\tbackupPath := filepath.Join(backupDir, backupName)\n\n\terr = os.WriteFile(backupPath, fileData, 0600)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to write backup file: %w\", err)\n\t}\n\n\tmetadata := BackupMetadata{\n\t\tFullPath:  absFilePath,\n\t\tTimestamp: now.Format(time.RFC3339),\n\t\tPerm:      fmt.Sprintf(\"%04o\", fileInfo.Mode().Perm()),\n\t}\n\n\tmetadataJSON, err := json.MarshalIndent(metadata, \"\", \"  \")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to marshal backup metadata: %w\", err)\n\t}\n\n\tmetadataName := fmt.Sprintf(\"%s.%s.%s.json\", basename, dirHash8, uuidStr)\n\tmetadataPath := filepath.Join(backupDir, metadataName)\n\n\terr = os.WriteFile(metadataPath, metadataJSON, 0600)\n\tif err != nil {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/filebackup/filebackup.go#L47-L83","documentation":"After creating the dated backup directory, MakeFileBackup writes the original file's contents to <basename>.<dirhash8>.<uuid>.bak with mode 0600 via os.WriteFile. This error wraps a failure of that write, meaning the backup file could not be created and the edit operation is aborted (no partial backup is returned).","triggerScenarios":"os.WriteFile(backupPath, fileData, 0600) fails: disk full, quota exceeded, backup dir deleted between MkdirAll and write, permission denied, or I/O error on the cache volume.","commonSituations":"Disk quota exceeded on the home/cache partition while backing up a large file; antivirus or backup software locking files (Windows); cache dir on a network mount that dropped; race with CleanupOldBackups or manual deletion.","solutions":["Free disk space on the volume holding the Wave caches dir and retry the edit.","Check permissions/ownership of the dated backup directory and ensure the process can create files in it.","Verify the file being backed up is not larger than available space/quota; if the cache volume is unreliable, point WAVE_HOME at a local disk.","Retry the operation; if it recurs, inspect OS logs for I/O errors on the cache volume."],"exampleFix":"// before\ndf -h ~/.cache  # disk full\n// after\nrm -rf ~/.cache/waveterm/waveai-backups/*/  # or free space, then retry the edit","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(filepath.Dir(wavebase.GetWaveCachesDir(), \"waveai-backups\")); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"backup path is not a directory\")\n}\n// optionally check free space before large edits","typeGuard":null,"tryCatchPattern":"backupPath, err := filebackup.MakeFileBackup(absPath)\nif err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, syscall.ENOSPC) {\n        return fmt.Errorf(\"disk full: free space before editing %s\", absPath)\n    }\n    return err\n}","preventionTips":["Keep headroom on the cache volume; large files double in usage when backed up","Exclude the cache dir from antivirus/backup software locking","Avoid network mounts for the Wave cache directory","Don't manually delete files in waveai-backups during edits"],"tags":["filesystem","disk-full","backup","go"],"backgroundTag":"file-write-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}