Tolerate individual plugin load errors

Summary: This diff fixes the issue when there is an error on checking GK for any of plugins and because of it the entire set of plugins failed to load. Each plugin should be loaded in isolation from others.

Reviewed By: passy

Differential Revision: D26099735

fbshipit-source-id: ba5475f4baf2d06f8922d345c9d401f5b15956ec
This commit is contained in:
Anton Nikolaev
2021-01-27 04:39:15 -08:00
committed by Facebook GitHub Bot
parent e104a1fa6b
commit 1ce619af7e

View File

@@ -162,6 +162,7 @@ export async function getDynamicPlugins() {
export const checkGK = (gatekeepedPlugins: Array<ActivatablePluginDetails>) => (
plugin: ActivatablePluginDetails,
): boolean => {
try {
if (!plugin.gatekeeper) {
return true;
}
@@ -170,21 +171,29 @@ export const checkGK = (gatekeepedPlugins: Array<ActivatablePluginDetails>) => (
gatekeepedPlugins.push(plugin);
}
return result;
} catch (err) {
console.error(`Failed to check GK for plugin ${plugin.id}`, err);
return false;
}
};
export const checkDisabled = (
disabledPlugins: Array<ActivatablePluginDetails>,
) => {
const enabledList = process.env.FLIPPER_ENABLED_PLUGINS
? new Set<string>(process.env.FLIPPER_ENABLED_PLUGINS.split(','))
: null;
let enabledList: Set<string> | null = null;
let disabledList: Set<string> = new Set();
try {
if (process.env.FLIPPER_ENABLED_PLUGINS) {
enabledList = new Set<string>(
process.env.FLIPPER_ENABLED_PLUGINS.split(','),
);
}
disabledList = config().disabledPlugins;
} catch (e) {
console.error(e);
console.error('Failed to compute enabled/disabled plugins', e);
}
return (plugin: ActivatablePluginDetails): boolean => {
try {
if (disabledList.has(plugin.name)) {
disabledPlugins.push(plugin);
return false;
@@ -201,6 +210,13 @@ export const checkDisabled = (
return false;
}
return true;
} catch (e) {
console.error(
`Failed to check whether plugin ${plugin.id} is disabled`,
e,
);
return false;
}
};
};