coreybutler/nvm-windows · error

fmt.Sprint(err) + ": " + stderr.String()

Error message

fmt.Sprint(err) + ": " + stderr.String()

What it means

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).

Source

Thrown at src/nvm.go:1897

	if err != nil {
		exe, _ := os.Executable()
		cmd := filepath.Join(filepath.Dir(exe), "elevate.cmd")
		ok, err = run(cmd, &env.root, append([]string{"cmd", "/C", name}, arg...)...)
	}

	return ok, err
}

func run(name string, dir *string, arg ...string) (bool, error) {
	c := exec.Command(name, arg...)
	if dir != nil {
		c.Dir = *dir
	}
	var stderr bytes.Buffer
	c.Stderr = &stderr
	err := c.Run()
	if err != nil {
		return false, errors.New(fmt.Sprint(err) + ": " + stderr.String())
	}

	return true, nil
}

func runElevated(command string, forceUAC ...bool) (bool, error) {
	uac := true //false
	if len(forceUAC) > 0 {
		uac = forceUAC[0]
	}

	if uac {
		// Alternative elevation option at stackoverflow.com/questions/31558066/how-to-ask-for-administer-privileges-on-windows-with-go
		cmd := exec.Command(filepath.Join(env.root, "elevate.cmd"), command)

		var output bytes.Buffer
		var _stderr bytes.Buffer
		cmd.Stdout = &output

View on GitHub (pinned to 5b18223ca1)

Solutions

  1. Read the text after the colon — it is the child process's stderr and names the actual failure
  2. Reproduce the failing child command manually in the same shell to see the full error
  3. If 'not found'-style: verify the executable exists and PATH/NVM_HOME are correct
  4. If permission-related: run the nvm command from an elevated terminal
  5. Temporarily disable overzealous antivirus/EDR interception of child processes and retry
Defensive patterns

Strategy: try-catch

Try / catch

ok, err := run("cmd.exe", nil, "/C", script)
if !ok {
    // err already embeds stderr; split for structured handling
    if idx := strings.LastIndex(err.Error(), ": "); idx > 0 {
        stderr := err.Error()[idx+2:]
        log.Printf("child stderr: %s", stderr)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15). Data as JSON: /api/errors/ccfff3266b3205ae. Report an issue: GitHub.