{"record":{"id":"6687fef6d8092d85","repo":"coreybutler/nvm-windows","slug":"failed-to-open-source-file-v","errorCode":null,"errorMessage":"failed to open source file: %v","messagePattern":"failed to open source file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade/upgrade.go","lineNumber":924,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer file.Close()\n\n\tvar checksum string\n\t_, err = fmt.Fscan(file, &checksum)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn checksum, nil\n}\n\nfunc copyFile(src, dst string) error {\n\t// Open the source file\n\tsourceFile, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %v\", err)\n\t}\n\tdefer sourceFile.Close()\n\n\t// Create the destination file\n\tdestinationFile, err := os.Create(dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %v\", err)\n\t}\n\tdefer destinationFile.Close()\n\n\t// Copy contents from the source file to the destination file\n\t_, err = io.Copy(destinationFile, sourceFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to copy file: %v\", err)\n\t}\n\n\t// Optionally, copy file permissions (this can be skipped if not needed)\n\tsourceInfo, err := os.Stat(src)","sourceCodeStart":906,"sourceCodeEnd":942,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/upgrade/upgrade.go#L906-L942","documentation":"copyFile is the workhorse used throughout the upgrade (backup zip, .update payloads, directory tree copy) and this is its first failure mode: os.Open(src) failed. On Windows the practical causes are the file not existing (an earlier step silently failed — many WriteFile/copyFile callers ignore errors) or the file being locked exclusively by another process.","triggerScenarios":"Source removed between listing and copy (race with cleanup/AV); source locked by a running process (node.exe, update.exe from a previous upgrade); path constructed from an asset name containing subdirectories that were never extracted; permissions on NVM_HOME files.","commonSituations":"Upgrading while node processes run; antivirus quarantine deleting the source; asset paths in the manifest not matching zip contents; partially completed prior upgrade leaving the tree inconsistent.","solutions":["Check that the logged src path actually exists (dir listing) — a missing file usually traces back to an earlier download/extract failure.","Close running node/nvm/update processes and retry.","Run as Administrator to rule out ACLs.","Repair the installation manually if the tree is inconsistent (reinstall nvm-windows)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check the source exists and is readable before copying\nif fi, err := os.Stat(src); err != nil {\n    return fmt.Errorf(\"source missing before copy: %s\", src)\n} else if fi.IsDir() {\n    return fmt.Errorf(\"source is a directory, expected file: %s\", src)\n}","typeGuard":null,"tryCatchPattern":"Wrap copyFile results with the src path in context; a failure here almost always traces to an earlier download/extract step — validate that step's outputs instead of retrying the copy blind.","preventionTips":["Verify downloads completed before copying.","Exclude nvm dirs from AV real-time scanning.","Stop processes that may hold the source file."],"tags":["filesystem","file-lock","upgrade","windows"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}