{"record":{"id":"1468ab7797e60edf","repo":"coreybutler/nvm-windows","slug":"failed-to-copy-file-w","errorCode":null,"errorMessage":"failed to copy file: %w","messagePattern":"failed to copy file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":34,"sourceCode":"\t}\n\n\t// Get file or directory info\n\tinfo, err := os.Stat(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to stat source: %w\", err)\n\t}\n\n\t// If old is a directory, copy recursively\n\tif info.IsDir() {\n\t\terr = copyDir(old, new)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy directory: %w\", err)\n\t\t}\n\t} else {\n\t\t// Otherwise, copy a single file\n\t\terr = copyFile(old, new)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy file: %w\", err)\n\t\t}\n\t}\n\n\t// Remove the original source\n\terr = os.RemoveAll(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to remove source: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// copyFile copies a single file from source (old) to destination (new).\nfunc copyFile(old, new string) error {\n\tsrcFile, err := os.Open(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %w\", err)\n\t}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L16-L52","documentation":"In Rename()'s cross-volume fallback, after os.Stat shows the source is a regular file, copyFile() is used to duplicate it. This error means the single-file copy failed at open, create, io.Copy, or chmod; the wrapped message names the precise step (open source / create destination / copy data / permissions).","triggerScenarios":"utility.Rename(old, new) across volumes where old is a file and the file cannot be read (locked by a running node.exe), the destination cannot be created (permissions, disk full), or io.Copy fails mid-stream.","commonSituations":"Renaming a node binary while it executes; destination directory on a FAT/exFAT drive where chmod semantics differ; insufficient disk space; destination path already exists as a read-only file.","solutions":["Close any process using the source file (check Task Manager for node.exe) and retry.","Inspect the wrapped error to identify the failing step and address it (free disk space, fix permissions).","Run the command elevated if destination creation is denied.","If chmod on the destination fails (non-NTFS filesystem), copy to an NTFS volume or relax the copy to skip Chmod on non-NTFS destinations."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(old); err != nil { return err } else if info.IsDir() == false { /* single-file path */ }","typeGuard":null,"tryCatchPattern":"if err := utility.Rename(old, new); err != nil {\n    if errors.Is(err, os.ErrPermission) { /* elevate and retry */ }\n    if errors.Is(err, syscall.ERROR_FILE_NOT_FOUND) { /* source gone: reinstall version */ }\n}","preventionTips":["Close processes using the file before cross-volume moves.","Check destination writability and space first.","Avoid moving node binaries that are currently executing."],"tags":["filesystem","copy","file","cross-volume","windows"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}