{"record":{"id":"8d0bb539d90388d7","repo":"coreybutler/nvm-windows","slug":"failed-to-copy-data-w","errorCode":null,"errorMessage":"failed to copy data: %w","messagePattern":"failed to copy data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":70,"sourceCode":"\t}\n\tdefer srcFile.Close()\n\n\t// Ensure destination directory exists\n\tdestDir := filepath.Dir(new)\n\terr = os.MkdirAll(destDir, os.ModePerm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory: %w\", err)\n\t}\n\n\tdestFile, err := os.Create(new)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %w\", err)\n\t}\n\tdefer destFile.Close()\n\n\t_, err = io.Copy(destFile, srcFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to copy data: %w\", err)\n\t}\n\n\t// Copy file permissions\n\tinfo, err := srcFile.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get source file info: %w\", err)\n\t}\n\terr = os.Chmod(new, info.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set permissions on destination file: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// copyDir recursively copies a directory from old path to new path.\nfunc copyDir(old, new string) error {\n\tentries, err := os.ReadDir(old)","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Compare free space with source size before copying\nfunc enoughSpace(dst string, need int64) bool {\n    var st syscall.Statfs_t // platform-specific; use golang.org/x/sys/windows GetDiskFreeSpaceEx on Windows\n    _ = st\n    return true // replace with real check\n}","typeGuard":null,"tryCatchPattern":"err := copyAcrossDrives(old, new)\nfor attempts := 0; err != nil && strings.Contains(err.Error(), \"failed to copy data\") && attempts < 3; attempts++ {\n    os.Remove(new) // drop partial file\n    time.Sleep(500 * time.Millisecond)\n    err = copyAcrossDrives(old, new)\n}","preventionTips":["Check destination free space before large cross-volume moves.","Delete partial destination files between retries.","Avoid copying to/from flaky removable media when possible."],"tags":["filesystem","io","copy","disk-space","windows"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}