Skip to content

CLI plugins error handling #109

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

Merged
merged 11 commits into from
May 20, 2025
Merged

CLI plugins error handling #109

merged 11 commits into from
May 20, 2025

Conversation

stanislavHamara
Copy link
Contributor

Problem Description

If a user has an old version of docker that does not include e.g. docker scout or docker ai commands and the extension relies on them, we just error out "silently" in the console.

Proposed Solution

This PR introduces an error message being shown when a particular sub command of docker is not available.

Proof of Work

TBD once we get a correct error message

@stanislavHamara stanislavHamara requested review from rcjsuen and Copilot and removed request for rcjsuen May 14, 2025 09:17
Copy link

@Copilot 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 plugins' error handling by providing explicit error messages when unsupported Docker subcommands are encountered. Key changes include:

  • Introducing a helper function (spawnDockerCommand) to handle Docker process spawning and error propagation.
  • Refactoring command registrations to use the new helper for both build and scout commands.
  • Updating settings and prompt logic to disable repetitive error prompts.

Reviewed Changes

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

Show a summary per file
File Description
src/utils/spawnDockerCommand.ts Adds a centralized function to spawn Docker commands and handle errors.
src/utils/settings.ts Provides helper functions to access and update Docker extension settings.
src/utils/prompt.ts Updates user prompt functions and introduces an error message function for unknown commands.
src/utils/os.ts Implements functions to determine the Docker Desktop path and verify its installation.
src/utils/monitor.ts Refactors Docker engine checking to use the new spawn helper and removes redundant logic.
src/extension.ts Refactors command registration to use the new spawn helper, ensuring consistent error handling.

): Promise<void> {
// TODO: Get a proper error message from Allie
await vscode.window.showErrorMessage(
`Docker Desktop does not know the command "${command}".`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aevesdocker could we please get an error message for when an extension tries to run a docker subcommand like docker scout or docker ai but it is not available because the user is running an older version of Docker Desktop from before that command was introduced?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is not available because the user is running an older version of Docker Desktop from before that command was introduced?

  1. It might be unavailable because the user installed Docker CE instead of installing Docker Desktop (likely case on Linux). We can reuse promptInstallDesktop in that case although the wording would be different of course.
  2. For the Docker Desktop prompts, Varun had mentioned to me we should show them based on the docker.extension.dockerEngineAvailabilityPrompt setting so we will need to add a conditional here similar to checkForDockerEngine. Sorry for not making that clear earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For 2 are we just happy with the fact that if the user sets docker.extension.dockerEngineAvailabilityPrompt to false they will not get a prompt regardless of if it's docker engine missing or they are running an unavailable command?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For 2 are we just happy with the fact that if the user sets docker.extension.dockerEngineAvailabilityPrompt to false they will not get a prompt regardless of if it's docker engine missing or they are running an unavailable command?

You got it. 👍 I think the idea is "if I have it set to false do not tell me to open or install or update Docker Desktop".

Copy link
Contributor

Choose a reason for hiding this comment

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

so we all good, or still need me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we still need one for the case:

It might be unavailable because the user installed Docker CE instead of installing Docker Desktop (likely case on Linux). We can reuse promptInstallDesktop in that case although the wording would be different of course.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can discuss this during standup to try and get a grasp on all the possibilities.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@stanislavHamara We have three different cases here:

  1. docker is not found and Node.js throws that ENOENT error
    • use the promptInstallDesktop function to prompt the user to install Docker Desktop if the user wants to be prompted (per getExtensionSetting('dockerEngineAvailabilityPrompt'))
  2. docker scout is not found and we get the non-zero exit code (which suggests docker itself is installed) and isDockerDesktopInstalled returns false, this is likely the Linux use case
    • similar to 1 above, we can prompt the user about this but we need a separate, distinct message from Allie first
  3. the reverse case of 2, isDockerDesktopInstalled returns true
    • as discussed on the call, this might not even be a real problem so we will just ignore this for now

@aevesdocker We need your help with 2 above.

const response = await vscode.window.showInformationMessage(
'Docker is not running. To get help with your Dockerfile, install Docker.',
"Don't show again",
'Install Docker Desktop',
);

To help jog your memory, these are the strings we use for the case where "Docker is not installed you should install Docker Desktop". This time we need a message to convey that Docker Scout could not be found and you can get it if you install Docker Desktop (without mentioning that Docker is not running as we know they have the docker CLI installed in this particular case).

If any of the above is unclear, please let me know. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

So something simple like

Docker Scout is not available. To access Docker Scout's features, install Docker Desktop.
with the same action options as above - Don't show again/Install Docker Desktop

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aevesdocker That sounds fine to me. 👍 Thanks!

Copy link
Collaborator

@rcjsuen rcjsuen left a comment

Choose a reason for hiding this comment

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

This refactoring is a good start and we can make further changes after this is merged.

@rcjsuen rcjsuen merged commit 6e5db37 into main May 20, 2025
12 checks passed
@rcjsuen rcjsuen deleted the cli-plugins-error-handling branch May 20, 2025 17:08
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