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:
parent
9b9b8e0d05
commit
e626cc91d4
@ -322,13 +322,12 @@ export class ExtensionLoader {
|
|||||||
this.instances.set(extId, instance);
|
this.instances.set(extId, instance);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extId,
|
|
||||||
instance,
|
instance,
|
||||||
isBundled: extension.isBundled,
|
installedExtension: extension,
|
||||||
activated: instance.activate(),
|
activated: instance.activate(),
|
||||||
};
|
};
|
||||||
} 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,9 +338,16 @@ 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) => {
|
||||||
|
logger.error(`${logModule}: activation extension error`, { ext: extension.installedExtension, error });
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Return ExtensionLoading[]
|
// Return ExtensionLoading[]
|
||||||
return extensions.map(extension => {
|
return extensions.map(extension => {
|
||||||
@ -350,7 +356,7 @@ export class ExtensionLoader {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isBundled: extension.isBundled,
|
isBundled: extension.installedExtension.isBundled,
|
||||||
loaded,
|
loaded,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -112,8 +112,7 @@ export class LensExtension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
async activate(): Promise<void> {
|
||||||
activate() {
|
|
||||||
return this.onActivate();
|
return this.onActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user