{"record":{"id":"b81a49cd6cab62c7","repo":"coreybutler/nvm-windows","slug":"failed-to-copy-subdirectory-w","errorCode":null,"errorMessage":"failed to copy subdirectory: %w","messagePattern":"failed to copy subdirectory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":106,"sourceCode":"\tentries, err := os.ReadDir(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read source directory: %w\", err)\n\t}\n\n\t// Ensure destination directory exists\n\terr = os.MkdirAll(new, os.ModePerm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory: %w\", err)\n\t}\n\n\tfor _, entry := range entries {\n\t\tsrcPath := filepath.Join(old, entry.Name())\n\t\tdestPath := filepath.Join(new, entry.Name())\n\n\t\tif entry.IsDir() {\n\t\t\terr = copyDir(srcPath, destPath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to copy subdirectory: %w\", err)\n\t\t\t}\n\t\t} else {\n\t\t\terr = copyFile(srcPath, destPath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to copy file: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":88,"sourceCodeEnd":118,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L88-L118","documentation":"Inside copyDir()'s entry loop, a nested directory is handled by a recursive copyDir(srcPath, destPath) call. This error means the recursion into a subdirectory failed; the wrapped chain (read source directory / create destination directory / copy file / ...) names the exact nested failure. Depth of nesting does not itself cause the error, but long resulting paths can.","triggerScenarios":"Recursive copy of a node version tree where some nested directory (e.g. node_modules\\<pkg>\\bin) cannot be read, its destination cannot be created, or any file inside it is locked/read-only.","commonSituations":"node_modules with deeply nested or locked packages; running node processes inside the tree; path length exceeding MAX_PATH (~260 chars) with long paths disabled; antivirus interference.","solutions":["Unwrap the error chain to the deepest cause and fix that specific entry (unlock file, free space, fix permissions).","Stop node/npm processes and retry.","Enable Windows long-path support for deep node_modules trees: set registry LongPathsEnabled=1.","Run elevated and add an antivirus exclusion for NVM_HOME."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-walk the tree to detect unreadable subdirectories before copying\nfilepath.WalkDir(old, func(p string, d fs.DirEntry, err error) error {\n    if err != nil { return fmt.Errorf(\"pre-check failed at %s: %w\", p, err) }\n    if d.IsDir() { if _, e := os.ReadDir(p); e != nil { return e } }\n    return nil\n})","typeGuard":null,"tryCatchPattern":"err := copyTree(old, new)\nif err != nil && strings.Contains(err.Error(), \"copy subdirectory\") {\n    killNodeProcesses()\n    err = copyTree(old, new) // one retry after unlocking\n}","preventionTips":["Enable Windows long paths for deep node_modules trees.","Stop node processes and exclude NVM_HOME from antivirus before moving.","Unwrap the chain to the failing subdirectory instead of restarting blind."],"tags":["filesystem","copy","recursion","directory","long-path"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}