{"record":{"id":"ccfff3266b3205ae","repo":"coreybutler/nvm-windows","slug":"fmt-sprint-err-stderr-string","errorCode":null,"errorMessage":"fmt.Sprint(err) + \": \" + stderr.String()","messagePattern":"fmt\\.Sprint\\(err\\) \\+ \": \" \\+ stderr\\.String\\(\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/nvm.go","lineNumber":1897,"sourceCode":"\tif err != nil {\n\t\texe, _ := os.Executable()\n\t\tcmd := filepath.Join(filepath.Dir(exe), \"elevate.cmd\")\n\t\tok, err = run(cmd, &env.root, append([]string{\"cmd\", \"/C\", name}, arg...)...)\n\t}\n\n\treturn ok, err\n}\n\nfunc run(name string, dir *string, arg ...string) (bool, error) {\n\tc := exec.Command(name, arg...)\n\tif dir != nil {\n\t\tc.Dir = *dir\n\t}\n\tvar stderr bytes.Buffer\n\tc.Stderr = &stderr\n\terr := c.Run()\n\tif err != nil {\n\t\treturn false, errors.New(fmt.Sprint(err) + \": \" + stderr.String())\n\t}\n\n\treturn true, nil\n}\n\nfunc runElevated(command string, forceUAC ...bool) (bool, error) {\n\tuac := true //false\n\tif len(forceUAC) > 0 {\n\t\tuac = forceUAC[0]\n\t}\n\n\tif uac {\n\t\t// Alternative elevation option at stackoverflow.com/questions/31558066/how-to-ask-for-administer-privileges-on-windows-with-go\n\t\tcmd := exec.Command(filepath.Join(env.root, \"elevate.cmd\"), command)\n\n\t\tvar output bytes.Buffer\n\t\tvar _stderr bytes.Buffer\n\t\tcmd.Stdout = &output","sourceCodeStart":1879,"sourceCodeEnd":1915,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/nvm.go#L1879-L1915","documentation":"Result of the internal run() helper wrapping every exec.Command failure: it concatenates the Go process error (e.g. 'exit status 1' or 'not found') with the command's captured stderr. It is a generic wrapper, so the underlying failing program and its stderr text are the real diagnostic; in this codebase it surfaces from elevated/child processes invoked during install/use (e.g. elevate.cmd, cmd /C rmdir).","triggerScenarios":"Any child process spawned via run(name, dir, args...) exiting non-zero or failing to start — missing executable (FileNotFound in err), permission denied, or the tool writing an error to stderr and returning a non-zero exit code.","commonSituations":"PATH missing cmd.exe helpers, antivirus blocking spawned processes, a wrapped batch script failing because of policy or missing files, or elevation helper scripts failing mid-way on locked files.","solutions":["Read the text after the colon — it is the child process's stderr and names the actual failure","Reproduce the failing child command manually in the same shell to see the full error","If 'not found'-style: verify the executable exists and PATH/NVM_HOME are correct","If permission-related: run the nvm command from an elevated terminal","Temporarily disable overzealous antivirus/EDR interception of child processes and retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"ok, err := run(\"cmd.exe\", nil, \"/C\", script)\nif !ok {\n    // err already embeds stderr; split for structured handling\n    if idx := strings.LastIndex(err.Error(), \": \"); idx > 0 {\n        stderr := err.Error()[idx+2:]\n        log.Printf(\"child stderr: %s\", stderr)\n    }\n}","preventionTips":["Validate that spawned executables exist and are on PATH before invoking run()","Capture and log stderr separately for diagnosability","Test child commands manually before wiring them into nvm flows"],"tags":["nvm-windows","exec","process","stderr","wrapper"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}