-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from all commits
01994e5
24387e7
90a7ad6
d9b923d
442c62f
f080cfe
282d559
01e60cb
a6afcbf
4e8ea21
23dc878
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { access } from 'fs'; | ||
import { spawnDockerCommand } from './spawnDockerCommand'; | ||
|
||
export function getDockerDesktopPath(): string { | ||
switch (process.platform) { | ||
case 'win32': | ||
return 'C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe'; | ||
case 'darwin': | ||
return '/Applications/Docker.app'; | ||
} | ||
return '/opt/docker-desktop/bin/com.docker.backend'; | ||
} | ||
|
||
export async function isDockerDesktopInstalled(): Promise<boolean> { | ||
return new Promise<boolean>((resolve) => { | ||
spawnDockerCommand('docker', ['desktop', 'version'], { | ||
onExit: (code) => { | ||
if (code === 0) { | ||
return resolve(true); | ||
} | ||
|
||
access(getDockerDesktopPath(), (err) => { | ||
resolve(err === null); | ||
}); | ||
}, | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||||||||
import * as vscode from 'vscode'; | ||||||||||||
import { spawn } from 'child_process'; | ||||||||||||
import { disableDockerEngineAvailabilityPrompt } from './settings'; | ||||||||||||
import { getDockerDesktopPath } from './os'; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Prompts the user to login to Docker Desktop. | ||||||||||||
*/ | ||||||||||||
export async function promptUnauthenticatedDesktop(): Promise<void> { | ||||||||||||
const response = await vscode.window.showInformationMessage( | ||||||||||||
'Docker is not running. To get help with your Dockerfile, sign in to Docker Desktop.', | ||||||||||||
"Don't show again", | ||||||||||||
); | ||||||||||||
if (response === "Don't show again") { | ||||||||||||
disableDockerEngineAvailabilityPrompt(); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Prompts the user to open Docker Desktop. | ||||||||||||
*/ | ||||||||||||
export async function promptOpenDockerDesktop(): Promise<void> { | ||||||||||||
const response = await vscode.window.showInformationMessage( | ||||||||||||
'Docker is not running. To get help with your Dockerfile, start Docker.', | ||||||||||||
"Don't show again", | ||||||||||||
'Open Docker Desktop', | ||||||||||||
); | ||||||||||||
if (response === "Don't show again") { | ||||||||||||
disableDockerEngineAvailabilityPrompt(); | ||||||||||||
} else if (response === 'Open Docker Desktop') { | ||||||||||||
const dockerDesktopPath = getDockerDesktopPath(); | ||||||||||||
if (process.platform === 'darwin') { | ||||||||||||
spawn('open', [dockerDesktopPath]).on('exit', (code) => { | ||||||||||||
if (code !== 0) { | ||||||||||||
vscode.window.showErrorMessage( | ||||||||||||
`Failed to open Docker Desktop: open ${dockerDesktopPath}`, | ||||||||||||
{ modal: true }, | ||||||||||||
); | ||||||||||||
} | ||||||||||||
}); | ||||||||||||
} else { | ||||||||||||
spawn(dockerDesktopPath).on('exit', (code) => { | ||||||||||||
if (code !== 0) { | ||||||||||||
vscode.window.showErrorMessage( | ||||||||||||
`Failed to open Docker Desktop: ${dockerDesktopPath}`, | ||||||||||||
{ modal: true }, | ||||||||||||
); | ||||||||||||
} | ||||||||||||
}); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Prompts the user to install Docker Desktop by navigating to the | ||||||||||||
* website. | ||||||||||||
*/ | ||||||||||||
export async function promptInstallDesktop(): Promise<void> { | ||||||||||||
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', | ||||||||||||
); | ||||||||||||
if (response === "Don't show again") { | ||||||||||||
disableDockerEngineAvailabilityPrompt(); | ||||||||||||
} else if (response === 'Install Docker Desktop') { | ||||||||||||
vscode.env.openExternal( | ||||||||||||
vscode.Uri.parse('https://docs.docker.com/install/'), | ||||||||||||
); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Shows a message to the user indicating that Docker Desktop does not know the command | ||||||||||||
*/ | ||||||||||||
export async function showUnknownCommandMessage( | ||||||||||||
command: string, | ||||||||||||
): Promise<void> { | ||||||||||||
// TODO: Get a proper error message from Allie | ||||||||||||
stanislavHamara marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
await vscode.window.showErrorMessage( | ||||||||||||
`Docker Desktop does not know the command "${command}".`, | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You got it. 👍 I think the idea is "if I have it set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we all good, or still need me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need one for the case:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stanislavHamara We have three different cases here:
@aevesdocker We need your help with 2 above. vscode-extension/src/utils/prompt.ts Lines 59 to 63 in 23dc878
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. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So something simple like
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aevesdocker That sounds fine to me. 👍 Thanks! |
||||||||||||
); | ||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.