{"record":{"id":"07e496f7557ebec6","repo":"coreybutler/nvm-windows","slug":"failed-to-create-destination-file-w","errorCode":null,"errorMessage":"failed to create destination file: %w","messagePattern":"failed to create destination file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":64,"sourceCode":"\n// copyFile copies a single file from source (old) to destination (new).\nfunc copyFile(old, new string) error {\n\tsrcFile, err := os.Open(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %w\", err)\n\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","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L46-L82","documentation":"In copyFile(), after the destination directory exists, os.Create(new) opens the destination file for writing. This error means creation failed: a file or directory already exists at that exact name with the wrong type/permissions, the volume is full, or the path is invalid. Note os.Create truncates an existing writable file, so a plain duplicate file does NOT trigger this — denial, not existence, is the usual cause.","triggerScenarios":"copyFile where the destination name is occupied by a read-only file or a directory, the destination volume is out of space, or the user lacks write permission on the destination folder.","commonSituations":"Previous nvm install left a read-only node.exe at the destination; disk full on the target drive; copying into a protected directory without elevation; leftover directory where a file is expected in the versions tree.","solutions":["Clear the read-only attribute on the destination file: attrib -r <dest>, or delete the stale destination and retry.","Free space on the destination volume if the wrapped error says insufficient disk space.","Run elevated for 'Access is denied'.","Remove any directory occupying the destination filename (rmdir) before retrying."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if info, err := os.Stat(new); err == nil && info.IsDir() {\n    return fmt.Errorf(\"destination %s is a directory, expected file\", new)\n}\n// clear read-only bit on stale destination\nos.Chmod(new, 0o666)","typeGuard":null,"tryCatchPattern":"if err := copyAcrossDrives(old, new); err != nil && strings.Contains(err.Error(), \"create destination file\") {\n    attrib := exec.Command(\"attrib\", \"-r\", new); attrib.Run()\n    err = copyAcrossDrives(old, new)\n}","preventionTips":["Remove stale read-only destination files before moving.","Keep destination disks from running full.","Elevate when writing into protected folders."],"tags":["filesystem","file-create","copy","windows","disk-space"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}