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 (#4805)

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

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Handle synchronous errors in onActivate

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Keep extensions that can't be activated in this.intances

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Return extensions that failed to be activated from loadExtensions to match old behavior.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Simplify style.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Simplify object. Remove unnecessary action.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2022-02-11 16:13:34 +02:00 committed by GitHub
parent 9b9b8e0d05
commit e626cc91d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -322,13 +322,12 @@ export class ExtensionLoader {
this.instances.set(extId, instance);
return {
extId,
instance,
isBundled: extension.isBundled,
installedExtension: extension,
activated: instance.activate(),
};
} 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) {
this.removeInstance(extId);
@ -339,9 +338,16 @@ export class ExtensionLoader {
// Remove null values
.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.
await Promise.all(extensions.map(extension => extension.activated));
await Promise.all(
extensions.map(extension =>
// If extension activation fails, log error
extension.activated.catch((error) => {
logger.error(`${logModule}: activation extension error`, { ext: extension.installedExtension, error });
}),
),
);
// Return ExtensionLoading[]
return extensions.map(extension => {
@ -350,7 +356,7 @@ export class ExtensionLoader {
});
return {
isBundled: extension.isBundled,
isBundled: extension.installedExtension.isBundled,
loaded,
};
});

View File

@ -112,8 +112,7 @@ export class LensExtension {
}
}
@action
activate() {
async activate(): Promise<void> {
return this.onActivate();
}