OpenNHP/opennhp · error

%s

Error message

%s

What it means

utils.Run executes an external command and captures stdout/stderr. If the command exits with an error it returns that error; if the command apparently succeeded but wrote anything to stderr, Run logs the stderr and fails the call with an error whose message is the raw stderr text (fmt.Errorf("%s", ...)). Any non-empty stderr is therefore treated as a failure even when the exit code was 0.

Solutions

  1. Run the command manually and inspect its stderr to see the actual message returned in the error
  2. Fix the invoked command/tool so it does not write to stderr on success (redirect its stderr to stdout or /dev/null in the wrapper script)
  3. If the stderr output is benign and you control the code, check the error string or switch to calling cmd.Run() directly with your own exit-code-only policy

Example fix

// before (called via utils.Run, fails on any stderr)
out, _, err := utils.Run("tool", "arg")
// after (tolerate warnings, keep output)
cmd := exec.Command("tool", "arg")
var stderr bytes.Buffer
cmd.Stderr = &stderr
err := cmd.Run()
// inspect stderr only if err != nil
Defensive patterns

Strategy: validation

Validate before calling

var b bytes.Buffer
cmd := exec.Command("tool", "args")
cmd.Stderr = &b
if err := cmd.Run(); err != nil { return err }
if b.Len() > 0 { log.Printf("tool stderr: %s", b.String()) } // handle warnings explicitly before using utils.Run

Try / catch

out, cmdStr, err := utils.Run("tool", "arg")
if err != nil {
    log.Printf("command %s failed with stderr: %v", cmdStr, err)
    return err
}

Prevention

When it happens

Trigger: A wrapped command writes warnings or informational messages to stderr while still producing correct stdout; or the command actually fails and cmd.Run() returns nil only in the exit-0-but-noisy case. The caller receives an error containing the tool's own stderr output as the message.

Common situations: CLI tools that print deprecation warnings or progress bars to stderr; scripts invoked by nhp that always emit a banner on stderr; tools whose success output partially goes to stderr.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/f586379b5a4f0804. Report an issue: GitHub.

Appendix: source

Thrown at nhp/utils/cmd.go:33

	defer cancel()
	c := make(chan string)
	defer close(c)
	var stderr bytes.Buffer
	var stdout bytes.Buffer

	cmd := exec.CommandContext(ctx, command, args...) //nolint:gosec // G204: Command args passed as separate parameters, not shell string
	cmd.Stderr = &stderr
	cmd.Stdout = &stdout
	if len(in) > 0 {
		cmd.Stdin = strings.NewReader(in)
	}
	err := cmd.Run()
	if err != nil {
		return "", cmd.String(), err
	}
	if stderr.String() != "" {
		log.Println(stderr.String())
		return "", cmd.String(), fmt.Errorf("%s", stderr.String())
	}

	res := strings.Replace(stdout.String(), "\n", "", -1)
	return res, cmd.String(), nil
}

View on GitHub (pinned to 6e04ca5ff0)