{"record":{"id":"e40f8401d9eaf99a","repo":"coreybutler/nvm-windows","slug":"error-failed-to-create-backup-directory-v","errorCode":null,"errorMessage":"error: failed to create backup directory: %v\n","messagePattern":"error: failed to create backup directory: (.+?)\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade/upgrade.go","lineNumber":469,"sourceCode":"\t// Debugging\n\tif verbose {\n\t\ttree(tmp, \"downloaded files (extracted):\")\n\t\tnvmtestcmd := exec.Command(filepath.Join(tmp, \"assets\", \"nvm.exe\"), \"version\")\n\t\tnvmtestcmd.Stdout = os.Stdout\n\t\tnvmtestcmd.Stderr = os.Stderr\n\t\terr = nvmtestcmd.Run()\n\t\tif err != nil {\n\t\t\tfmt.Println(\"error running nvm.exe:\", err)\n\t\t}\n\t}\n\n\t// Backup current version to zip\n\tstatus <- Status{Text: \"applying update...\"}\n\tcurrentExe, _ := os.Executable()\n\tcurrentPath := filepath.Dir(currentExe)\n\tbkp, err := os.MkdirTemp(\"\", \"nvm-backup-*\")\n\tif err != nil {\n\t\tstatus <- Status{Err: fmt.Errorf(\"error: failed to create backup directory: %v\\n\", err)}\n\t}\n\tdefer os.RemoveAll(bkp)\n\n\terr = zipDirectory(currentPath, filepath.Join(bkp, \"backup.zip\"))\n\tif err != nil {\n\t\tstatus <- Status{Err: fmt.Errorf(\"error: failed to create backup: %v\\n\", err)}\n\t}\n\n\tos.MkdirAll(filepath.Join(currentPath, \".update\"), os.ModePerm)\n\tcopyFile(filepath.Join(bkp, \"backup.zip\"), filepath.Join(currentPath, \".update\", \"nvm4w-backup.zip\"))\n\n\t// Copy the new files to the current directory\n\t// copyFile(currentExe, fmt.Sprintf(\"%s.%s.bak\", currentExe, version))\n\tcopyDirContents(filepath.Join(tmp, \"assets\"), currentPath)\n\tcopyFile(filepath.Join(tmp, \"assets\", \"nvm.exe\"), filepath.Join(currentPath, \".update/nvm.exe\"))\n\n\tif verbose {\n\t\tnvmtestcmd := exec.Command(filepath.Join(currentPath, \".update/nvm.exe\"), \"version\")","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/upgrade/upgrade.go#L451-L487","documentation":"Before overwriting the current installation, nvm-windows creates a second temp directory (nvm-backup-*) to hold a zip of the existing version. This error means os.MkdirTemp failed, i.e. the OS refused to create a directory under %TEMP%. Nothing has been modified yet at this point, so the installation is still intact.","triggerScenarios":"TEMP/TMP environment variable pointing at a non-existent or unwritable directory; disk full on the temp drive; TEMP directory ACLs restricted (locked-down corporate machine); process running without rights to write to the resolved temp path.","commonSituations":"System drive full (most common on small VMs/CI); TEMP redirected to a ramdisk or network share that is unavailable; group policy restricting %TEMP% write access for the invoking user.","solutions":["Free space on the drive hosting %TEMP% (often C:) and retry.","Verify TEMP/TMP: echo %TEMP% then confirm the directory exists and you can create a folder in it.","Run the upgrade from an elevated shell if ACLs are blocking directory creation.","As a workaround set TEMP/TMP to a writable local path before running nvm."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Guarantee a writable temp root before upgrading\nif err := os.MkdirTemp(\"\", \"nvm-probe-*\"); err != nil {\n    fmt.Println(\"TEMP not writable:\", err)\n    os.Setenv(\"TEMP\", `D:\\nvm-tmp`) // point somewhere writable\n}","typeGuard":null,"tryCatchPattern":"Fail fast and clean — nothing has been modified when this fires. Report TEMP path and suggest freeing space or redirecting TEMP.","preventionTips":["Keep the system drive from filling completely.","Verify TEMP/TMP point at existing, writable local directories.","Run upgrades elevated on locked-down machines."],"tags":["filesystem","temp","upgrade","windows"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}