{"record":{"id":"5ed73535a470703d","repo":"coreybutler/nvm-windows","slug":"failed-to-open-source-file-w","errorCode":null,"errorMessage":"failed to open source file: %w","messagePattern":"failed to open source file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":51,"sourceCode":"\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}\n\tdefer srcFile.Close()\n\n\t// Ensure destination directory exists\n\tdestDir := filepath.Dir(new)\n\terr = os.MkdirAll(destDir, os.ModePerm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory: %w\", err)\n\t}\n\n\tdestFile, err := os.Create(new)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %w\", err)\n\t}\n\tdefer destFile.Close()\n\n\t_, err = io.Copy(destFile, srcFile)\n\tif err != nil {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L33-L69","documentation":"First step of copyFile(): os.Open on the source file failed. The wrapped *PathError gives the OS reason — most commonly the file does not exist, is locked by a running process, or access is denied. Nothing has been written to the destination yet when this fires.","triggerScenarios":"copyFile(old, new) called from Rename() or copyDir() where 'old' was removed between ReadDir/stat and open, is held with an exclusive lock (running executable), or the user lacks read permission.","commonSituations":"Copying a node version whose node.exe is currently executing; racing with another nvm command deleting the same tree; long paths over 260 chars without long-path support enabled.","solutions":["Close/kill processes using the file (node.exe, npm, editors) and retry.","Verify the path exists immediately before the copy; if it vanished, a concurrent nvm operation raced you — re-run install/use.","Run elevated for 'Access is denied' errors.","Enable Windows long paths (LongPathsEnabled=1) for deep node_modules paths."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if f, err := os.Open(old); err != nil { return fmt.Errorf(\"source unreadable: %w\", err) } else { f.Close() }","typeGuard":null,"tryCatchPattern":"if err := copyAcrossDrives(old, new); err != nil {\n    if errors.Is(err, os.ErrNotExist) { /* re-run nvm install to restore source */ }\n    if errors.Is(err, os.ErrPermission) { /* elevate or unlock file */ }\n}","preventionTips":["Ensure no node.exe from the version directory is running.","Pre-open source files to validate readability before starting a large copy.","Run one nvm operation at a time."],"tags":["filesystem","file-open","copy","windows"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}