coreybutler/nvm-windows · error

failed to copy file: %w

Error message

failed to copy file: %w

What it means

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).

Source

Thrown at src/utility/rename.go:34

	}

	// Get file or directory info
	info, err := os.Stat(old)
	if err != nil {
		return fmt.Errorf("failed to stat source: %w", err)
	}

	// If old is a directory, copy recursively
	if info.IsDir() {
		err = copyDir(old, new)
		if err != nil {
			return fmt.Errorf("failed to copy directory: %w", err)
		}
	} else {
		// Otherwise, copy a single file
		err = copyFile(old, new)
		if err != nil {
			return fmt.Errorf("failed to copy file: %w", err)
		}
	}

	// Remove the original source
	err = os.RemoveAll(old)
	if err != nil {
		return fmt.Errorf("failed to remove source: %w", err)
	}

	return nil
}

// copyFile copies a single file from source (old) to destination (new).
func copyFile(old, new string) error {
	srcFile, err := os.Open(old)
	if err != nil {
		return fmt.Errorf("failed to open source file: %w", err)
	}

View on GitHub (pinned to 5b18223ca1)

Solutions

  1. Close any process using the source file (check Task Manager for node.exe) and retry.
  2. Inspect the wrapped error to identify the failing step and address it (free disk space, fix permissions).
  3. Run the command elevated if destination creation is denied.
  4. 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.
Defensive patterns

Strategy: try-catch

Validate before calling

if info, err := os.Stat(old); err != nil { return err } else if info.IsDir() == false { /* single-file path */ }

Try / catch

if err := utility.Rename(old, new); err != nil {
    if errors.Is(err, os.ErrPermission) { /* elevate and retry */ }
    if errors.Is(err, syscall.ERROR_FILE_NOT_FOUND) { /* source gone: reinstall version */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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