1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Don't block other extensions from loading if one activation fails.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2022-02-03 11:11:08 +02:00
parent 6ebfd76644
commit 4f89f08a70
2 changed files with 26 additions and 13 deletions

View File

@ -324,11 +324,13 @@ export class ExtensionLoader {
return { return {
extId, extId,
instance, instance,
installedExtension: extension,
isBundled: extension.isBundled, isBundled: extension.isBundled,
activated: instance.activate(), activated: instance.activate(),
activationError: null,
}; };
} catch (err) { } catch (err) {
logger.error(`${logModule}: activation extension error`, { ext: extension, err }); logger.error(`${logModule}: error loading extension`, { ext: extension, err });
} }
} else if (!extension.isEnabled && alreadyInit) { } else if (!extension.isEnabled && alreadyInit) {
this.removeInstance(extId); this.removeInstance(extId);
@ -339,12 +341,23 @@ export class ExtensionLoader {
// Remove null values // Remove null values
.filter(extension => Boolean(extension)); .filter(extension => Boolean(extension));
// We first need to wait until each extension's `onActivate` is resolved, // We first need to wait until each extension's `onActivate` is resolved or rejected,
// as this might register new catalog categories. Afterwards we can safely .enable the extension. // as this might register new catalog categories. Afterwards we can safely .enable the extension.
await Promise.all(extensions.map(extension => extension.activated)); await Promise.all(
extensions.map(extension =>
// If extension activation fails, log error
extension.activated.catch((error) => {
extension.activationError = error;
logger.error(`${logModule}: activation extension error`, { ext: extension.installedExtension, error });
this.instances.delete(extension.extId);
}),
),
);
// Return ExtensionLoading[] // Return ExtensionLoading[]
return extensions.map(extension => { return extensions
.filter(extension =>!extension.activationError)
.map(extension => {
const loaded = extension.instance.enable(register).catch((err) => { const loaded = extension.instance.enable(register).catch((err) => {
logger.error(`${logModule}: failed to enable`, { ext: extension, err }); logger.error(`${logModule}: failed to enable`, { ext: extension, err });
}); });

View File

@ -114,7 +114,7 @@ export class LensExtension {
@action @action
activate() { activate() {
return this.onActivate(); return Promise.resolve(this.onActivate());
} }
protected onActivate(): Promise<void> | void { protected onActivate(): Promise<void> | void {