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:
parent
6ebfd76644
commit
4f89f08a70
@ -324,11 +324,13 @@ export class ExtensionLoader {
|
||||
return {
|
||||
extId,
|
||||
instance,
|
||||
installedExtension: extension,
|
||||
isBundled: extension.isBundled,
|
||||
activated: instance.activate(),
|
||||
activationError: null,
|
||||
};
|
||||
} 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,21 +341,32 @@ 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) => {
|
||||
extension.activationError = error;
|
||||
logger.error(`${logModule}: activation extension error`, { ext: extension.installedExtension, error });
|
||||
this.instances.delete(extension.extId);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
// Return ExtensionLoading[]
|
||||
return extensions.map(extension => {
|
||||
const loaded = extension.instance.enable(register).catch((err) => {
|
||||
logger.error(`${logModule}: failed to enable`, { ext: extension, err });
|
||||
});
|
||||
return extensions
|
||||
.filter(extension =>!extension.activationError)
|
||||
.map(extension => {
|
||||
const loaded = extension.instance.enable(register).catch((err) => {
|
||||
logger.error(`${logModule}: failed to enable`, { ext: extension, err });
|
||||
});
|
||||
|
||||
return {
|
||||
isBundled: extension.isBundled,
|
||||
loaded,
|
||||
};
|
||||
});
|
||||
return {
|
||||
isBundled: extension.isBundled,
|
||||
loaded,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
protected autoInitExtensions(register: (ext: LensExtension) => Promise<Disposer[]>) {
|
||||
|
||||
@ -114,7 +114,7 @@ export class LensExtension {
|
||||
|
||||
@action
|
||||
activate() {
|
||||
return this.onActivate();
|
||||
return Promise.resolve(this.onActivate());
|
||||
}
|
||||
|
||||
protected onActivate(): Promise<void> | void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user