{"record":{"id":"b80ed7163587c7ee","repo":"coreybutler/nvm-windows","slug":"failed-to-get-relative-path-for-s-v","errorCode":null,"errorMessage":"failed to get relative path for %s: %v","messagePattern":"failed to get relative path for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade/upgrade.go","lineNumber":972,"sourceCode":"\n// copyDirContents copies all the contents (files and subdirectories) of a source directory to a destination directory.\nfunc copyDirContents(srcDir, dstDir string) error {\n\t// Ensure destination directory exists\n\terr := os.MkdirAll(dstDir, 0755)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory %s: %v\", dstDir, err)\n\t}\n\n\t// Walk through the source directory recursively\n\terr = filepath.Walk(srcDir, func(srcPath string, info os.FileInfo, err error) error {\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error accessing %s: %v\", srcPath, err)\n\t\t}\n\n\t\t// Construct the corresponding path in the destination directory\n\t\trelPath, err := filepath.Rel(srcDir, srcPath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get relative path for %s: %v\", srcPath, err)\n\t\t}\n\n\t\tdstPath := filepath.Join(dstDir, relPath)\n\n\t\t// If it's a directory, ensure it's created in the destination\n\t\tif info.IsDir() {\n\t\t\treturn os.MkdirAll(dstPath, info.Mode())\n\t\t}\n\n\t\t// If it's a file, copy it\n\t\treturn copyFile(srcPath, dstPath)\n\t})\n\n\treturn err\n}\n\n// zipDirectory zips the contents of a directory.\nfunc zipDirectory(sourceDir, outputZip string) error {","sourceCodeStart":954,"sourceCodeEnd":990,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/upgrade/upgrade.go#L954-L990","documentation":"Inside the copyDirContents walk callback, filepath.Rel(srcDir, srcPath) computes the destination-relative path and this error means that call failed. In practice Rel fails only when srcDir and srcPath cannot be related — one is absolute and the other relative, or a volume separator mismatch (C: vs D:) sneaks in. Within the documented flow it is near-unreachable; when seen, it indicates malformed path inputs (UNC vs drive-letter mixing, empty srcDir) rather than an environment problem.","triggerScenarios":"srcDir passed as a UNC path (\\\\server\\share) while Walk yields drive-letter paths or vice versa; srcDir empty or relative while Walk returns absolute paths; volume-relative paths (C:foo without a slash) appearing in the tree; cwd changing mid-walk.","commonSituations":"NVM_HOME configured as a UNC/network path so extracted paths and base path disagree; manually invoking the copy routine with mismatched path forms; exotic junction/symlink layouts inside the extracted tree.","solutions":["Normalize both srcDir and the walk root to absolute cleaned paths with filepath.Abs/filepath.Clean before walking.","Avoid UNC paths for NVM_HOME; map the share to a drive letter or use a local directory.","Log srcDir and the failing srcPath at error time (add them to the message) to confirm the mismatch.","Retry after relocating the operation to a local filesystem path."],"exampleFix":"// before\nrelPath, err := filepath.Rel(srcDir, srcPath)\n\n// after: normalize the base once, outside the callback\nsrcRoot, err := filepath.Abs(srcDir)\nif err != nil { return err }\n...\nrelPath, err := filepath.Rel(srcRoot, srcPath)\nif err != nil {\n    return fmt.Errorf(\"failed to get relative path for %s under %s: %v\", srcPath, srcRoot, err)\n}","handlingStrategy":"validation","validationCode":"// Normalize the walk root once, and reject un-relatable inputs\nsrcRoot, err := filepath.Abs(srcDir)\nif err != nil || srcRoot == \"\" {\n    return fmt.Errorf(\"invalid source dir: %q\", srcDir)\n}\n// later: filepath.Rel(srcRoot, filepath.Clean(srcPath))","typeGuard":null,"tryCatchPattern":"This is a programming-error class failure: catch, include both paths in the message, and stop — retrying cannot fix mismatched path forms. Fix the caller to pass normalized absolute paths.","preventionTips":["Always filepath.Abs both sides before walking.","Avoid UNC/mixed drive-letter path forms for NVM_HOME.","Reject empty or volume-relative path inputs early."],"tags":["filesystem","paths","windows","upgrade"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}