wavetermdev/waveterm · error
failed to delete file: %w
Error message
failed to delete file: %w
What it means
DeleteAppFile removes the resolved file with os.Remove and wraps any failure (waveappstore.go:335-337). Note that on POSIX os.Remove can delete directories too, but the common failure is the file not existing (fs.ErrNotExist) or lacking write permission on the containing directory.
Source
Thrown at pkg/waveappstore/waveappstore.go:336
}
func DeleteAppFile(appId string, fileName string) error {
if err := ValidateAppId(appId); err != nil {
return fmt.Errorf("invalid appId: %w", err)
}
appDir, err := GetAppDir(appId)
if err != nil {
return err
}
filePath, err := validateAndResolveFilePath(appDir, fileName)
if err != nil {
return err
}
if err := os.Remove(filePath); err != nil {
return fmt.Errorf("failed to delete file: %w", err)
}
return nil
}
func ReplaceInAppFile(appId string, fileName string, edits []fileutil.EditSpec) error {
if err := ValidateAppId(appId); err != nil {
return fmt.Errorf("invalid appId: %w", err)
}
appDir, err := GetAppDir(appId)
if err != nil {
return err
}
filePath, err := validateAndResolveFilePath(appDir, fileName)
if err != nil {
return errView on GitHub (pinned to a4447c1563)
Solutions
- Check errors.Is(err, fs.ErrNotExist) and treat as success if you want idempotent deletes.
- If permission denied, fix write permission on the app directory (you need write on the dir, not the file).
- Verify the app/file exists first with ListAllAppFiles or os.Stat.
- If the filesystem is read-only, remount rw or free the disk and retry.
Example fix
// before: non-idempotent delete
cleanup := func() error { return waveappstore.DeleteAppFile(appId, "tmp.out") }
// after: tolerate already-deleted files
if err := waveappstore.DeleteAppFile(appId, "tmp.out"); err != nil && !errors.Is(err, fs.ErrNotExist) {
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
func filePresent(appId, fileName string) bool {
dir, err := waveappstore.GetAppDir(appId)
if err != nil { return false }
_, err = os.Stat(filepath.Join(dir, filepath.Clean(fileName)))
return err == nil
} Try / catch
err := waveappstore.DeleteAppFile(appId, fileName)
if err != nil && errors.Is(err, fs.ErrNotExist) {
return nil // already deleted — idempotent success
}
if err != nil {
return err
} Prevention
- Make deletes idempotent by accepting fs.ErrNotExist.
- You need write permission on the app directory, not the file itself.
- Check existence first if you must report 'deleted' vs 'not found' differently.
- Handle read-only-filesystem errors distinctly from not-found.
When it happens
Trigger: Calling DeleteAppFile (or DeleteAppFileCommand) for a fileName that does not exist in the app dir; deleting a file inside a directory the user cannot write; deleting a non-empty directory entry or a file on a read-only filesystem.
Common situations: Double-delete after a first successful delete (idempotency bug); deleting files generated by the build that were already cleaned up; permissions broken by running the app under a different user; ENOSPC-adjacent read-only remount after disk errors.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- failed to stat file: %w
- accessing file %s: %w
- file does not exist: %q
- removing file: %w
- cannot access image file: %v
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/fde0f20b6c07ac58.
Report an issue: GitHub.