Skip to content

Executing workbench.extensions.installExtension command with an invalid extension ID\Path swallows all exceptions #88713

Closed

Description

  • VSCode Version: 1.41.1
  • OS Version: Windows 10 (Build 19546(
    We have a private extension that cannot be placed in the private gallery and we have our own update mechanism for our extension.

Previously it was re-launching VSCode (new process) to install\update the extension but it was pointed out to us that executing the ''workbench.extensions.installExtension' command also works. (The ms-vscode.cpptools extension does this already). However, while ensuring that this technique would work for our extension, I discovered that exceptions from the command implementations in src\vs\workbench\contrib\extensions\browser\extensions.contribution.ts where being "logged" but not "re-thrown" to the command executor.

We would like to leverage this command (instead of having to re-spawn VSCode) but we also have a very strong desire to know when things fail, so we haven't converted our code yet.

Steps to Reproduce:

try {
            await commands.executeCommand('workbench.extensions.installExtension', Uri.file('c:\\windows\\system32\\ntdll.dll'));
} catch (e) {
   console.log(JSON.stringify(e));
}

Does this issue occur when all extensions are disabled?: Yes

Possible fix is to pass in an optional boolean parameter to re-throw the error if the users desires:

I'll issue a pull request for this fix and we can go from there.

CommandsRegistry.registerCommand({
	id: 'workbench.extensions.installExtension',
	description: {
		description: localize('workbench.extensions.installExtension.description', "Install the given extension"),
		args: [
			{
				name: localize('workbench.extensions.installExtension.arg.name', "Extension id or VSIX resource uri"),
				schema: {
					'type': ['object', 'string']
				}
			},
			{
				name: localize('workbench.extensions.installExtension.arg.throwOnFailure', "Indicates whether to re-throw any exception as well as log it"),
				schema: {
					'type' : 'boolean'
				}
			}
		]
	},
	handler: async (accessor, extensionId: string | UriComponents, throwOnFailure?: boolean) => {
		const extensionManagementService = accessor.get(IExtensionManagementService);
		const extensionGalleryService = accessor.get(IExtensionGalleryService);
		try {
			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.", extensionId));
				}
			} else {
				const vsix = URI.revive(extensionId);
				await extensionManagementService.install(vsix);
			}
		} catch (e) {
			onUnexpectedError(e);
			if (throwOnFailure) {
				throw e;
			}
		}
	}
``` TypeScript

Activity

  1. added
    extensions
    on Jan 15, 2020
  2. added
    bug
    on Jan 21, 2020
  3. dbaeumer commented on Jan 30, 2020

    @dbaeumer
    Member

    Verified using

    try {
    	await vscode.commands.executeCommand('workbench.extensions.installExtension', vscode.Uri.file('c:\\windows\\system32\\ntdll.dll'), true);
    } catch (e) {
    	console.log(JSON.stringify(e));
    }
  4. locked and limited conversation to collaborators on Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugextensionsverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions