Skip to content

Show command on failure#1600

Open
xverges wants to merge 6 commits intodapr:masterfrom
xverges:xv-show-failing-command
Open

Show command on failure#1600
xverges wants to merge 6 commits intodapr:masterfrom
xverges:xv-show-failing-command

Conversation

@xverges
Copy link

@xverges xverges commented Mar 1, 2026

Description

  • Make failures on subcommands more informative by displaying the command that triggered them and the exit code
  • Prevent potential deadlock by using exec.cmd.Output rather than sequentially reading stdout and stderr
./dapr init --container-runtime podman
⌛  Making the jump to hyperspace...
ℹ️  Container images will be pulled from Docker Hub
ℹ️  Installing runtime version 1.17.0
❌  Downloading binaries and setting up components...
❌  error running "podman run --name dapr_placement --restart always -d --entrypoint ./placement -p 50005:50005 -p 58080:8080 -p 59090:9090 docker.io/daprio/dapr:1.17.0" (exit code 126): Error: something went wrong with the request: "proxy already running\n"

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #1594

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: Xavier Vergés <github@verg.es>
@xverges xverges requested review from a team as code owners March 1, 2026 10:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the CLI’s diagnostics when invoking external subcommands by including the triggering command (and intended exit code) in failure messages, and simplifies process execution to avoid potential stdout/stderr pipe deadlocks.

Changes:

  • Refactor RunCmdAndWait to use exec.Cmd.Output() and to format richer errors that include the command string and (when available) the exit code and captured output.
  • Add unit tests covering success and multiple failure modes (stderr present, stdout-only, no output).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
utils/utils.go Reworks RunCmdAndWait execution + error formatting to surface command/output/exit code and avoid pipe read deadlocks.
utils/utils_test.go Adds coverage for the new RunCmdAndWait behavior across success and failure scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Xavier Vergés <xverges@gmail.com>
Signed-off-by: Xavier Vergés <github@verg.es>
@xverges xverges marked this pull request as draft March 5, 2026 18:59
Signed-off-by: Xavier Vergés <github@verg.es>
@xverges xverges marked this pull request as ready for review March 5, 2026 19:07
}

resp, err := io.ReadAll(stdout)
resp, err := cmd.Output()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes a bit what ends up in the returned string because resp will now contain the stderr as well (if exit is 0), while previously we only had the stdout from the command if I'm not mistaken.
I think it's better but I'd like to hear from @dapr/maintainers-cli

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that what you are describing is CombinedOutput. From https://pkg.go.dev/os/exec#Cmd.Output

Output runs the command and returns its standard output. Any returned error will usually be of type *ExitError. If c.Stderr was nil and the returned error is of type *ExitError, Output populates the Stderr field of the returned error.

FWIW, I had the same understanding as you until I checked the docs a minute ago :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool, I was wrong then. In this case, I think the behavior is the same as previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dapr cli could be more helpful reporting docker/podman errors

4 participants