coreybutler/nvm-windows · error
failed to copy data: %w
Error message
failed to copy data: %w
What it means
In copyFile(), io.Copy(destFile, srcFile) streams the file contents. This error means the byte transfer failed partway — destination writes failed (disk full, quota exceeded) or the source read failed (I/O error, file truncated underneath, handle invalidated). The destination file may be left partially written.
Source
Thrown at src/utility/rename.go:70
}
defer srcFile.Close()
// Ensure destination directory exists
destDir := filepath.Dir(new)
err = os.MkdirAll(destDir, os.ModePerm)
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)View on GitHub (pinned to 5b18223ca1)
Solutions
- Check the wrapped error for 'There is not enough space on the disk' and free space, then retry.
- If the source is on removable/network media, verify it is still mounted and readable, then retry.
- Delete the partially-written destination file before retrying so sizes can be compared afterward.
- Run chkdsk on the suspect volume if repeated I/O errors occur.
Defensive patterns
Strategy: retry
Validate before calling
// Compare free space with source size before copying
func enoughSpace(dst string, need int64) bool {
var st syscall.Statfs_t // platform-specific; use golang.org/x/sys/windows GetDiskFreeSpaceEx on Windows
_ = st
return true // replace with real check
} Try / catch
err := copyAcrossDrives(old, new)
for attempts := 0; err != nil && strings.Contains(err.Error(), "failed to copy data") && attempts < 3; attempts++ {
os.Remove(new) // drop partial file
time.Sleep(500 * time.Millisecond)
err = copyAcrossDrives(old, new)
} Prevention
- Check destination free space before large cross-volume moves.
- Delete partial destination files between retries.
- Avoid copying to/from flaky removable media when possible.
When it happens
Trigger: copyFile where the destination disk fills mid-copy, the source file is on a failing/removable drive that disappears, or an antivirus/filter driver aborts the read/write.
Common situations: Moving a large node version (node_modules with big binaries) to a nearly-full drive; USB/network drive dropouts; source on a drive with bad sectors; WebDAV/network filesystem timeouts.
Related errors
- failed to create destination file: %w
- failed to copy directory: %w
- failed to copy file: %w
- failed to open source file: %w
- failed to create destination directory: %w
AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15).
Data as JSON: /api/errors/8d0bb539d90388d7.
Report an issue: GitHub.