{"record":{"id":"74d380c886980ad8","repo":"wavetermdev/waveterm","slug":"failed-to-rename-file-w","errorCode":null,"errorMessage":"failed to rename file: %w","messagePattern":"failed to rename file: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/waveappstore/waveappstore.go","lineNumber":403,"sourceCode":"\t\treturn err\n\t}\n\n\tfromPath, err := validateAndResolveFilePath(appDir, fromFileName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid source path: %w\", err)\n\t}\n\n\ttoPath, err := validateAndResolveFilePath(appDir, toFileName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid destination path: %w\", err)\n\t}\n\n\tif err := os.MkdirAll(filepath.Dir(toPath), 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory: %w\", err)\n\t}\n\n\tif err := os.Rename(fromPath, toPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to rename file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc FormatGoFile(appId string, fileName string) error {\n\tif err := ValidateAppId(appId); err != nil {\n\t\treturn fmt.Errorf(\"invalid appId: %w\", err)\n\t}\n\n\tappDir, err := GetAppDir(appId)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfilePath, err := validateAndResolveFilePath(appDir, fileName)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/waveappstore/waveappstore.go#L385-L421","documentation":"RenameAppFile performs the actual os.Rename(fromPath, toPath) after validating both paths and creating the destination directory. If the kernel-level rename fails, the error is wrapped as \"failed to rename file\". Common causes are the source file being missing/locked or the two paths residing on different filesystems.","triggerScenarios":"os.Rename fails because fromPath no longer exists (deleted by another process), the file is open/locked on Windows, or source and destination are on different mounts/devices (EXDEV).","commonSituations":"Renaming a file concurrently with a delete or app removal; syncing waveapps across a mountpoint; on Windows, an editor or virus scanner holding the file open.","solutions":["Confirm the source file exists with os.Stat(fromPath) before renaming","Retry the rename — transient locks (Windows AV, editor) often clear quickly; implement retry with backoff","Fall back to copy+delete if the error is cross-device (EXDEV)","Check permissions/locks on both files; close any process holding the source open"],"exampleFix":"// before\nerr := RenameAppFile(appId, from, to)\n// after\nif _, err := os.Stat(fromPath); err == nil {\n    err = RenameAppFile(appId, from, to)\n}","handlingStrategy":"retry","validationCode":"if _, err := os.Stat(fromPath); os.IsNotExist(err) {\n\treturn fmt.Errorf(\"source file %s does not exist\", fromPath)\n}","typeGuard":null,"tryCatchPattern":"var lastErr error\nfor i := 0; i < 3; i++ {\n\terr := RenameAppFile(appId, from, to)\n\tif err == nil {\n\t\tbreak\n\t}\n\tif !strings.Contains(err.Error(), \"failed to rename file\") {\n\t\treturn err\n\t}\n\tlastErr = err\n\ttime.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)\n}\nreturn lastErr","preventionTips":["Verify the source file exists immediately before renaming","Avoid concurrent delete/rename operations on the same app file","On Windows, close editors/handles holding the file before renaming","Fall back to copy+delete when the error indicates a cross-device move"],"tags":["filesystem","rename","go"],"backgroundTag":"rename-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}