Fix error handling in plugin loading
Summary: If a device plugin throw an error in it's initialization, it would prevent the device itself from being registered. This fixes that. As shown in the comments of for example: https://fb.workplace.com/groups/flippersupport/permalink/1218627761951213/ Reviewed By: ananyaarun Differential Revision: D31127969 fbshipit-source-id: 9824d23b275f1f9e866f841035961e4707ff8e04
This commit is contained in:
committed by
Facebook GitHub Bot
parent
40f20f6785
commit
a72e46c792
@@ -32,6 +32,7 @@ import {
|
||||
getFlipperLib,
|
||||
timeout,
|
||||
ClientQuery,
|
||||
_SandyPluginDefinition,
|
||||
} from 'flipper-plugin';
|
||||
import {freeze} from 'immer';
|
||||
import GK from './fb-stubs/GK';
|
||||
@@ -210,17 +211,7 @@ export default class Client extends EventEmitter {
|
||||
this.plugins.forEach((pluginId) => {
|
||||
const plugin = this.getPlugin(pluginId);
|
||||
if (plugin) {
|
||||
// TODO: needs to be wrapped in error tracking T68955280
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyPluginInstance(
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
||||
initialStates[pluginId],
|
||||
),
|
||||
);
|
||||
this.loadPlugin(plugin, initialStates[pluginId]);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
@@ -237,6 +228,26 @@ export default class Client extends EventEmitter {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
loadPlugin(
|
||||
plugin: _SandyPluginDefinition,
|
||||
initialState?: Record<string, any>,
|
||||
) {
|
||||
try {
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyPluginInstance(
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
||||
initialState,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(`Failed to start plugin '${plugin.id}': `, e);
|
||||
}
|
||||
}
|
||||
|
||||
startPluginIfNeeded(
|
||||
plugin: PluginDefinition | undefined,
|
||||
isEnabled = plugin ? this.isEnabledPlugin(plugin.id) : false,
|
||||
@@ -247,16 +258,7 @@ export default class Client extends EventEmitter {
|
||||
(isEnabled || defaultEnabledBackgroundPlugins.includes(plugin.id)) &&
|
||||
!this.sandyPluginStates.has(plugin.id)
|
||||
) {
|
||||
// TODO: needs to be wrapped in error tracking T68955280
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyPluginInstance(
|
||||
getFlipperLib(),
|
||||
plugin,
|
||||
this,
|
||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
||||
),
|
||||
);
|
||||
this.loadPlugin(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -306,6 +306,7 @@ export default class BaseDevice implements Device {
|
||||
}
|
||||
this.hasDevicePlugins = true;
|
||||
if (plugin instanceof _SandyPluginDefinition) {
|
||||
try {
|
||||
this.sandyPluginStates.set(
|
||||
plugin.id,
|
||||
new _SandyDevicePluginInstance(
|
||||
@@ -317,6 +318,9 @@ export default class BaseDevice implements Device {
|
||||
initialState,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(`Failed to start device plugin '${plugin.id}': `, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user