coreybutler/nvm-windows · warning

failed to get source file info: %w

Error message

failed to get source file info: %w

What it means

In copyFile(), after data is copied, srcFile.Stat() fetches the source's FileInfo so its permission mode can be cloned to the destination. This error means that stat call failed — rare, because the same handle was just read successfully. It usually indicates the file was deleted/renamed underneath the open handle or a filesystem-level fault.

Source

Thrown at src/utility/rename.go:76

	if err != nil {
		return fmt.Errorf("failed to create destination directory: %w", err)
	}

	destFile, err := os.Create(new)
	if err != nil {
		return fmt.Errorf("failed to create destination file: %w", err)
	}
	defer destFile.Close()

	_, err = io.Copy(destFile, srcFile)
	if err != nil {
		return fmt.Errorf("failed to copy data: %w", err)
	}

	// Copy file permissions
	info, err := srcFile.Stat()
	if err != nil {
		return fmt.Errorf("failed to get source file info: %w", err)
	}
	err = os.Chmod(new, info.Mode())
	if err != nil {
		return fmt.Errorf("failed to set permissions on destination file: %w", err)
	}

	return nil
}

// copyDir recursively copies a directory from old path to new path.
func copyDir(old, new string) error {
	entries, err := os.ReadDir(old)
	if err != nil {
		return fmt.Errorf("failed to read source directory: %w", err)
	}

	// Ensure destination directory exists
	err = os.MkdirAll(new, os.ModePerm)

View on GitHub (pinned to 5b18223ca1)

Solutions

  1. Retry the operation with no concurrent nvm commands running (close other terminals using nvm).
  2. Add antivirus exclusions for the NVM_HOME directory to prevent mid-copy quarantine.
  3. If on removable media, verify the media's integrity and re-copy.
  4. As a code-level fix, fall back to the FileInfo from the earlier os.Stat or skip Chmod when this stat fails (permissions are non-critical on Windows).

Example fix

// before
info, err := srcFile.Stat()
if err != nil {
    return fmt.Errorf("failed to get source file info: %w", err)
}

// after: reuse the stat info Rename() already obtained, or tolerate failure
info, err := srcFile.Stat()
if err != nil {
    // Non-fatal on Windows: destination already holds the data.
    return nil
}
Defensive patterns

Strategy: fallback

Validate before calling

if _, err := os.Stat(old); err != nil { return err } // perform once, reuse FileInfo

Try / catch

if err := copyAcrossDrives(old, new); err != nil && strings.Contains(err.Error(), "source file info") {
    // data already copied; permission clone failed — accept the copy
    err = nil
}

Prevention

When it happens

Trigger: copyFile where, between opening/copying and stat-ing, the source is deleted by a concurrent process, or the underlying volume suffers an I/O error.

Common situations: Two nvm commands racing on the same version directory; antivirus quarantining the source file mid-operation; flaky removable media.

Related errors


AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15). Data as JSON: /api/errors/aa79f5b2855ab92c. Report an issue: GitHub.