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

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

Closed
GabeDeBacker opened this issue Jan 15, 2020 · 1 comment · Fixed by #88714
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug extensions Issues concerning extensions verified Verification succeeded
Milestone

Comments

@GabeDeBacker
Copy link
Contributor

  • 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
@vscodebot vscodebot bot added the extensions Issues concerning extensions label Jan 15, 2020
@sandy081 sandy081 added the bug Issue identified by VS Code Team member as probable bug label Jan 21, 2020
@sandy081 sandy081 added this to the January 2020 milestone Jan 21, 2020
@dbaeumer dbaeumer added the verified Verification succeeded label Jan 30, 2020
@dbaeumer
Copy link
Member

dbaeumer commented Jan 30, 2020

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));
}

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug extensions Issues concerning extensions verified Verification succeeded
Projects
None yet
3 participants