Repository navigation
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
dbaeumer commentedon Jan 30, 2020
Verified using