Skip to content

fix(hooks): ensure command errors are displayed before CLI hooks#7071

Open
mohithshuka wants to merge 2 commits into
docker:masterfrom
mohithshuka:fix/error-hooks-ordering
Open

fix(hooks): ensure command errors are displayed before CLI hooks#7071
mohithshuka wants to merge 2 commits into
docker:masterfrom
mohithshuka:fix/error-hooks-ordering

Conversation

@mohithshuka

Copy link
Copy Markdown

This PR fixes the ordering of CLI hook output and command errors.

Currently, when a command fails, the "What's next" hook message is printed
before the actual error, which can confuse users.

Changes

  • Ensure command errors are displayed before CLI hooks.

  • Preserve the existing hook functionality.

  • Improve the readability of CLI output in failure scenarios.

  • Reviewed the execution flow of runDocker()

  • Verified that command errors are emitted before hook output

  • No changes to public APIs

Fixes #6973

mohithshuka added 2 commits June 14, 2026 16:55
The --filter flag description for 'docker volume prune' only mentioned
'label=<label>' but not 'label!=<label>', even though the label!
filter is supported and handled correctly by the underlying
PruneFilters function.

This commit:
- Updates the --filter flag description to include label!=<label>
- Adds a unit test for the label! filter to match the existing
  label filter test

Fixes docker#6918

Signed-off-by: mohithshuka <YOUR_ID+mohithshuka@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 17:10

Copilot AI left a comment

Copy link
Copy Markdown

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 aims to improve CLI UX by ensuring command failure errors are displayed before any “What’s next” (CLI hook) output, preventing hooks from visually preceding the actual error message.

Changes:

  • Adjusts the runDocker() execution flow to print command errors before running CLI command hooks.
  • Updates docker volume prune help text to mention label!=... filters.
  • Adds a label!=... test-case and golden output for volume prune.

Reviewed changes

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

File Description
cmd/docker/docker.go Attempts to change the ordering between command errors and CLI hooks (currently introduces a compilation issue).
cli/command/volume/prune.go Expands filter help text to include label!=<label>.
cli/command/volume/prune_test.go Adds coverage for --filter label!=... behavior.
cli/command/volume/testdata/volume-prune-success.label-not-filter.golden Adds golden output for the new label-not-filter test case.

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

Comment thread cmd/docker/docker.go
Comment on lines 546 to 550
// If the command is being executed in an interactive terminal
// and hook are enabled, run the plugin hooks.
if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() {
if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() _ = dockerCli.Err().Flush(){
pluginmanager.RunCLICommandHooks(ctx, dockerCli, cmd, subCommand, cmdErrorMessage(err))
}
Comment on lines 58 to 61
flags.SetAnnotation("all", "version", []string{"1.42"})
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.Var(&options.filter, "filter", `Provide filter values (e.g. "label=<label>")`)
flags.Var(&options.filter, "filter", `Provide filter values (e.g. "label=<label>" or "label!=<label>")`)

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.

Error hooks are printed before command output

2 participants