Skip to content

Conversation

@derekmisler
Copy link

@derekmisler derekmisler commented Feb 11, 2026

This PR is part of a trilogy:

  1. docker/cli <-- you are here
  2. docker/ai
  3. docker/pinata

Closes https://github.com/docker/gordon/issues/125

- What I did

Enabled CLI plugin hooks to fire on command failure, not just success. Previously, when a plugin-delegated command like docker build (buildx) or docker compose up failed, the hooks system was skipped entirely. This meant plugins like ai, scout, and debug could never show "What's next:" hints for failed builds or compose errors, which is exactly when our users would benefit from a docker ai "fix my problem" command.

- How I did it

Two changes:

  1. cli-plugins/manager/hooks.go: Added cmdErrorMessage string parameter to RunPluginHooks, forwarding it to runHooks instead of hardcoding "". This makes it symmetric with RunCLICommandHooks, which already accepts error messages.
  2. cmd/docker/docker.go: Moved the plugin hooks invocation outside the if err == nil block so it fires regardless of plugin exit status. The error message is extracted the same way the native command path already does it.

- How to verify it

  1. Register a plugin with hooks for a plugin-delegated command (e.g., buildx build):
# In ~/.docker/config.json, ensure:
# "features": { "hooks": "true" }
# "plugins": { "<plugin>": { "hooks": "buildx build" } }
  1. Before this change — run a failing build, observe no "What's next:" hints:
echo "FROM nonexistent:image" > /tmp/Dockerfile
docker build /tmp
# No hints shown
  1. After this change — same failing build now shows plugin hints:
docker build /tmp
# "What's next:" hints from registered plugins appear
  1. Verify successful commands still show hints (no regression):
docker build -t test -f /dev/null .  # or any successful build
# Hooks fire with empty error message, same as before
  1. Verify native commands are unaffected:
docker run nonexistent:image
# Hooks fire on failure (worked before, still works)

@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/docker/docker.go 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@derekmisler derekmisler force-pushed the cli-hints-for-docker-ai-after-buildcompose-failur branch 2 times, most recently from 6847b55 to 2641288 Compare February 11, 2026 19:11
@thaJeztah
Copy link
Member

cc @vvoland @laurazard looks related to what was implemented in;

@derekmisler derekmisler force-pushed the cli-hints-for-docker-ai-after-buildcompose-failur branch from 2641288 to 1c23ad4 Compare February 11, 2026 19:50
@derekmisler
Copy link
Author

cc @vvoland @laurazard looks related to what was implemented in;

Yeah, that PR was helpful when working on this one. I saw we were hard-coding an empty "" in place of the error here: https://github.com/docker/cli/pull/5033/changes#diff-7e76b3d50db2ee696d1cdbaa3f1e429b179da962bb8f308960ef85bc0ba835a2R43

@derekmisler derekmisler force-pushed the cli-hints-for-docker-ai-after-buildcompose-failur branch 7 times, most recently from 12ab446 to b1e39b0 Compare February 11, 2026 21:35
@derekmisler derekmisler marked this pull request as ready for review February 11, 2026 21:36
@derekmisler
Copy link
Author

I'm not sure about that e2e test, @thaJeztah, it passes sometimes and fails others, and I can't figure out why.

Signed-off-by: Derek Misler <derek.misler@docker.com>
@derekmisler derekmisler force-pushed the cli-hints-for-docker-ai-after-buildcompose-failur branch from b1e39b0 to 19b66c8 Compare February 11, 2026 22:02
@thaJeztah
Copy link
Member

Yeah, that test is rather flaky; not an issue with this PR; I restarted CI.

Yeah, that PR was helpful when working on this one. I saw we were hard-coding an empty "" in place of the error here

Yup; I mostly pinged @vvoland and @laurazard to check if they recalled there was a specific reason; there was this line in the PR description;

This is only available for CLI command executions.

And I do recall there was some chatter at the the about some risks with hook being triggered recursively (with a growing number of plugins, there's also a growing amount of overhead).

// RunPluginHooks is the entrypoint for the hooks execution flow
// after a plugin command was just executed by the CLI.
func RunPluginHooks(ctx context.Context, dockerCLI config.Provider, rootCmd, subCommand *cobra.Command, args []string) {
func RunPluginHooks(ctx context.Context, dockerCLI config.Provider, rootCmd, subCommand *cobra.Command, args []string, cmdErrorMessage string) {
Copy link
Member

Choose a reason for hiding this comment

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

Just so I don't forget; this function is exported (and may be in use elsewhere), so we probably can't change the signature.

Copy link
Author

Choose a reason for hiding this comment

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

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.

3 participants