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

don't choke whole settings download if an extension fails to install #1435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export default class Commons {
files: File[],
removedExtensions: ExtensionInformation[],
addedExtensions: ExtensionInformation[],
failedToAddExtensions: ExtensionInformation[],
ignoredExtensions: ExtensionInformation[],
syncSettings: LocalConfig
) {
Expand Down Expand Up @@ -524,6 +525,19 @@ export default class Commons {
});
}

if (failedToAddExtensions) {
outputChannel.appendLine(``);
outputChannel.appendLine(`Extensions Failed to be Added:`);

if (addedExtensions.length === 0) {
outputChannel.appendLine(` No extensions failed to add.`);
}

failedToAddExtensions.forEach(extn => {
outputChannel.appendLine(` ${extn.name} v${extn.version}`);
});
}

outputChannel.appendLine(`--------------------`);
outputChannel.append(`Done.`);
outputChannel.show(true);
Expand Down
64 changes: 44 additions & 20 deletions src/service/plugin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ export class ExtensionMetadata {
) {}
}

export interface ExtensionsInstallInfo {
addedExtensions: ExtensionInformation[];
failedToAddExtensions: ExtensionInformation[];
}

export const getDefaultExtensionsInstallInfo = (): ExtensionsInstallInfo => ({
addedExtensions: [],
failedToAddExtensions: [],
});

export class PluginService {
public static GetMissingExtensions(
remoteExt: string,
Expand Down Expand Up @@ -190,28 +200,28 @@ export class PluginService {
extensions: string,
ignoredExtensions: string[],
notificationCallBack: (...data: any[]) => void
): Promise<ExtensionInformation[]> {
let addedExtensions: ExtensionInformation[] = [];
): Promise<ExtensionsInstallInfo> {
const missingExtensions = PluginService.GetMissingExtensions(
extensions,
ignoredExtensions
);
if (missingExtensions.length === 0) {
notificationCallBack("Sync : No Extensions needs to be installed.");
return [];
return getDefaultExtensionsInstallInfo();
}
addedExtensions = await PluginService.InstallWithAPI(
const installInfo: ExtensionsInstallInfo = await PluginService.InstallWithAPI(
missingExtensions,
notificationCallBack
);
return addedExtensions;
return installInfo;
}

public static async InstallWithAPI(
missingExtensions: ExtensionInformation[],
notificationCallBack: (...data: any[]) => void
): Promise<ExtensionInformation[]> {
): Promise<ExtensionsInstallInfo> {
const addedExtensions: ExtensionInformation[] = [];
const failedToAddExtensions: ExtensionInformation[] = [];
const missingExtensionsCount = missingExtensions.length;
notificationCallBack("TOTAL EXTENSIONS : " + missingExtensionsCount);
notificationCallBack("");
Expand All @@ -221,23 +231,37 @@ export class PluginService {
try {
notificationCallBack("");
notificationCallBack(`[x] - EXTENSION: ${ext.name} - INSTALLING`);
await vscode.commands.executeCommand(
"workbench.extensions.installExtension",
name
);
notificationCallBack("");
notificationCallBack(`[x] - EXTENSION: ${ext.name} INSTALLED.`);
notificationCallBack(
` ${missingExtensions.indexOf(ext) +
1} OF ${missingExtensionsCount} INSTALLED`,
true
);
notificationCallBack("");
addedExtensions.push(ext);

let success = true;
try {
await vscode.commands.executeCommand(
"workbench.extensions.installExtension",
name
);
} catch (err) {
notificationCallBack("");
notificationCallBack(`[x] - EXTENSION: ${ext.name} FAILED TO INSTALL:`);
notificationCallBack(err);

success = false;
failedToAddExtensions.push(ext);
}

if (success) {
notificationCallBack("");
notificationCallBack(`[x] - EXTENSION: ${ext.name} INSTALLED.`);
notificationCallBack(
` ${missingExtensions.indexOf(ext) +
1} OF ${missingExtensionsCount} INSTALLED`,
true
);
notificationCallBack("");
addedExtensions.push(ext);
}
} catch (err) {
throw new Error(err);
}
}
return addedExtensions;
return { addedExtensions, failedToAddExtensions };
}
}
7 changes: 5 additions & 2 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export class Sync {
allSettingFiles,
null,
uploadedExtensions,
null,
ignoredExtensions,
localConfig
);
Expand Down Expand Up @@ -466,6 +467,7 @@ export class Sync {
}

let addedExtensions: ExtensionInformation[] = [];
let failedToAddExtensions: ExtensionInformation[] = [];
let deletedExtensions: ExtensionInformation[] = [];
const ignoredExtensions: string[] =
customSettings.ignoreExtensions || new Array<string>();
Expand Down Expand Up @@ -603,7 +605,7 @@ export class Sync {
Commons.outputChannel.show();
}

addedExtensions = await PluginService.InstallExtensions(
({ addedExtensions, failedToAddExtensions } = await PluginService.InstallExtensions(
content,
ignoredExtensions,
(message: string, dispose: boolean) => {
Expand All @@ -619,7 +621,7 @@ export class Sync {
}
}
}
);
));
} catch (err) {
throw new Error(err);
}
Expand Down Expand Up @@ -702,6 +704,7 @@ export class Sync {
updatedFiles,
deletedExtensions,
addedExtensions,
failedToAddExtensions,
null,
localSettings
);
Expand Down