Skip to content
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

Allows extension install and uninstall command execution to throw exceptions back to caller #88714

Merged
Expand Up @@ -228,30 +228,31 @@ CommandsRegistry.registerCommand({
description: localize('workbench.extensions.installExtension.description', "Install the given extension"),
args: [
{
name: localize('workbench.extensions.installExtension.arg.name', "Extension id or VSIX resource uri"),
name: localize('workbench.extensions.installExtension.extensionId.name', "Extension id or VSIX resource uri"),
schema: {
'type': ['object', 'string']
}
}
]
},
handler: async (accessor, arg: string | UriComponents) => {
handler: async (accessor, extensionId: string | UriComponents) => {
const extensionManagementService = accessor.get(IExtensionManagementService);
const extensionGalleryService = accessor.get(IExtensionGalleryService);
try {
if (typeof arg === 'string') {
const extension = await extensionGalleryService.getCompatibleExtension({ id: arg });
if (typeof extensionId === 'string') {
const extension = await extensionGalleryService.getCompatibleExtension({ id: extensionId });
if (extension) {
await extensionManagementService.installFromGallery(extension);
} else {
throw new Error(localize('notFound', "Extension '{0}' not found.", arg));
throw new Error(localize('notFound', "Extension '{0}' not found.", extensionId));
}
} else {
const vsix = URI.revive(arg);
const vsix = URI.revive(extensionId);
await extensionManagementService.install(vsix);
}
} catch (e) {
onUnexpectedError(e);
throw e;
}
}
});
Expand All @@ -262,28 +263,29 @@ CommandsRegistry.registerCommand({
description: localize('workbench.extensions.uninstallExtension.description', "Uninstall the given extension"),
args: [
{
name: localize('workbench.extensions.uninstallExtension.arg.name', "Id of the extension to uninstall"),
name: localize('workbench.extensions.uninstallExtension.extensionId.name', "Id of the extension to uninstall"),
schema: {
'type': 'string'
}
}
]
},
handler: async (accessor, id: string) => {
if (!id) {
handler: async (accessor, extensionId: string) => {
if (!extensionId) {
throw new Error(localize('id required', "Extension id required."));
}
const extensionManagementService = accessor.get(IExtensionManagementService);
const installed = await extensionManagementService.getInstalled(ExtensionType.User);
const [extensionToUninstall] = installed.filter(e => areSameExtensions(e.identifier, { id }));
const [extensionToUninstall] = installed.filter(e => areSameExtensions(e.identifier, { id: extensionId }));
if (!extensionToUninstall) {
throw new Error(localize('notInstalled', "Extension '{0}' is not installed. Make sure you use the full extension ID, including the publisher, e.g.: ms-vscode.csharp.", id));
throw new Error(localize('notInstalled', "Extension '{0}' is not installed. Make sure you use the full extension ID, including the publisher, e.g.: ms-vscode.csharp.", extensionId));
}

try {
await extensionManagementService.uninstall(extensionToUninstall, true);
} catch (e) {
onUnexpectedError(e);
throw e;
}
}
});
Expand Down