From 1ce619af7ef748cc683b013985c69c361595f0f7 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Wed, 27 Jan 2021 04:39:15 -0800 Subject: [PATCH] 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 --- desktop/app/src/dispatcher/plugins.tsx | 66 ++++++++++++++++---------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/desktop/app/src/dispatcher/plugins.tsx b/desktop/app/src/dispatcher/plugins.tsx index 5a855c24b..c02b57315 100644 --- a/desktop/app/src/dispatcher/plugins.tsx +++ b/desktop/app/src/dispatcher/plugins.tsx @@ -162,45 +162,61 @@ export async function getDynamicPlugins() { export const checkGK = (gatekeepedPlugins: Array) => ( plugin: ActivatablePluginDetails, ): boolean => { - if (!plugin.gatekeeper) { - return true; + try { + if (!plugin.gatekeeper) { + return true; + } + const result = GK.get(plugin.gatekeeper); + if (!result) { + gatekeepedPlugins.push(plugin); + } + return result; + } catch (err) { + console.error(`Failed to check GK for plugin ${plugin.id}`, err); + return false; } - const result = GK.get(plugin.gatekeeper); - if (!result) { - gatekeepedPlugins.push(plugin); - } - return result; }; export const checkDisabled = ( disabledPlugins: Array, ) => { - const enabledList = process.env.FLIPPER_ENABLED_PLUGINS - ? new Set(process.env.FLIPPER_ENABLED_PLUGINS.split(',')) - : null; + let enabledList: Set | null = null; let disabledList: Set = new Set(); try { + if (process.env.FLIPPER_ENABLED_PLUGINS) { + enabledList = new Set( + 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 => { - if (disabledList.has(plugin.name)) { - disabledPlugins.push(plugin); + try { + if (disabledList.has(plugin.name)) { + disabledPlugins.push(plugin); + return false; + } + if ( + enabledList && + !( + enabledList.has(plugin.name) || + enabledList.has(plugin.id) || + enabledList.has(plugin.name.replace('flipper-plugin-', '')) + ) + ) { + disabledPlugins.push(plugin); + return false; + } + return true; + } catch (e) { + console.error( + `Failed to check whether plugin ${plugin.id} is disabled`, + e, + ); return false; } - if ( - enabledList && - !( - enabledList.has(plugin.name) || - enabledList.has(plugin.id) || - enabledList.has(plugin.name.replace('flipper-plugin-', '')) - ) - ) { - disabledPlugins.push(plugin); - return false; - } - return true; }; };