coreybutler/nvm-windows · error
failed to open source file: %v
Error message
failed to open source file: %v
What it means
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.
Source
Thrown at src/upgrade/upgrade.go:924
if err != nil {
return "", err
}
defer file.Close()
var checksum string
_, err = fmt.Fscan(file, &checksum)
if err != nil {
return "", err
}
return checksum, nil
}
func copyFile(src, dst string) error {
// Open the source file
sourceFile, err := os.Open(src)
if err != nil {
return fmt.Errorf("failed to open source file: %v", err)
}
defer sourceFile.Close()
// Create the destination file
destinationFile, err := os.Create(dst)
if err != nil {
return fmt.Errorf("failed to create destination file: %v", err)
}
defer destinationFile.Close()
// Copy contents from the source file to the destination file
_, err = io.Copy(destinationFile, sourceFile)
if err != nil {
return fmt.Errorf("failed to copy file: %v", err)
}
// Optionally, copy file permissions (this can be skipped if not needed)
sourceInfo, err := os.Stat(src)View on GitHub (pinned to 5b18223ca1)
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).
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check the source exists and is readable before copying
if fi, err := os.Stat(src); err != nil {
return fmt.Errorf("source missing before copy: %s", src)
} else if fi.IsDir() {
return fmt.Errorf("source is a directory, expected file: %s", src)
} Try / catch
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.
Prevention
- Verify downloads completed before copying.
- Exclude nvm dirs from AV real-time scanning.
- Stop processes that may hold the source file.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to create destination file: %v
- error: failed to create backup directory: %v
- error: failed to create backup: %v
- error: failed to copy update.exe: %v
- failed to create destination directory %s: %v
AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15).
Data as JSON: /api/errors/6687fef6d8092d85.
Report an issue: GitHub.