-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix: run plugin hooks on command failure, not just success #6794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix: run plugin hooks on command failure, not just success #6794
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
6847b55 to
2641288
Compare
|
cc @vvoland @laurazard looks related to what was implemented in; |
2641288 to
1c23ad4
Compare
Yeah, that PR was helpful when working on this one. I saw we were hard-coding an empty |
12ab446 to
b1e39b0
Compare
|
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>
b1e39b0 to
19b66c8
Compare
|
Yeah, that test is rather flaky; not an issue with this PR; I restarted CI.
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;
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only implementation site I could find: https://github.com/docker/cli/pull/6794/changes#diff-3dcd6325b70a5f5db393a3ecc08060b69007fcef371fb4dabf3164da95646fb6R488
This PR is part of a trilogy:
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) ordocker compose upfailed, the hooks system was skipped entirely. This meant plugins likeai,scout, anddebugcould never show "What's next:" hints for failed builds or compose errors, which is exactly when our users would benefit from adocker ai "fix my problem"command.- How I did it
Two changes:
cli-plugins/manager/hooks.go: AddedcmdErrorMessagestring parameter toRunPluginHooks, forwarding it torunHooksinstead of hardcoding"". This makes it symmetric withRunCLICommandHooks, which already accepts error messages.cmd/docker/docker.go: Moved the plugin hooks invocation outside theif err == nilblock 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