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,
|
getFlipperLib,
|
||||||
timeout,
|
timeout,
|
||||||
ClientQuery,
|
ClientQuery,
|
||||||
|
_SandyPluginDefinition,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {freeze} from 'immer';
|
import {freeze} from 'immer';
|
||||||
import GK from './fb-stubs/GK';
|
import GK from './fb-stubs/GK';
|
||||||
@@ -210,17 +211,7 @@ export default class Client extends EventEmitter {
|
|||||||
this.plugins.forEach((pluginId) => {
|
this.plugins.forEach((pluginId) => {
|
||||||
const plugin = this.getPlugin(pluginId);
|
const plugin = this.getPlugin(pluginId);
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
// TODO: needs to be wrapped in error tracking T68955280
|
this.loadPlugin(plugin, initialStates[pluginId]);
|
||||||
this.sandyPluginStates.set(
|
|
||||||
plugin.id,
|
|
||||||
new _SandyPluginInstance(
|
|
||||||
getFlipperLib(),
|
|
||||||
plugin,
|
|
||||||
this,
|
|
||||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
|
||||||
initialStates[pluginId],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
@@ -237,6 +228,26 @@ export default class Client extends EventEmitter {
|
|||||||
return plugins;
|
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(
|
startPluginIfNeeded(
|
||||||
plugin: PluginDefinition | undefined,
|
plugin: PluginDefinition | undefined,
|
||||||
isEnabled = plugin ? this.isEnabledPlugin(plugin.id) : false,
|
isEnabled = plugin ? this.isEnabledPlugin(plugin.id) : false,
|
||||||
@@ -247,16 +258,7 @@ export default class Client extends EventEmitter {
|
|||||||
(isEnabled || defaultEnabledBackgroundPlugins.includes(plugin.id)) &&
|
(isEnabled || defaultEnabledBackgroundPlugins.includes(plugin.id)) &&
|
||||||
!this.sandyPluginStates.has(plugin.id)
|
!this.sandyPluginStates.has(plugin.id)
|
||||||
) {
|
) {
|
||||||
// TODO: needs to be wrapped in error tracking T68955280
|
this.loadPlugin(plugin);
|
||||||
this.sandyPluginStates.set(
|
|
||||||
plugin.id,
|
|
||||||
new _SandyPluginInstance(
|
|
||||||
getFlipperLib(),
|
|
||||||
plugin,
|
|
||||||
this,
|
|
||||||
getPluginKey(this.id, {serial: this.query.device_id}, plugin.id),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,17 +306,21 @@ export default class BaseDevice implements Device {
|
|||||||
}
|
}
|
||||||
this.hasDevicePlugins = true;
|
this.hasDevicePlugins = true;
|
||||||
if (plugin instanceof _SandyPluginDefinition) {
|
if (plugin instanceof _SandyPluginDefinition) {
|
||||||
this.sandyPluginStates.set(
|
try {
|
||||||
plugin.id,
|
this.sandyPluginStates.set(
|
||||||
new _SandyDevicePluginInstance(
|
plugin.id,
|
||||||
getFlipperLib(),
|
new _SandyDevicePluginInstance(
|
||||||
plugin,
|
getFlipperLib(),
|
||||||
this,
|
plugin,
|
||||||
// break circular dep, one of those days again...
|
this,
|
||||||
getPluginKey(undefined, {serial: this.serial}, plugin.id),
|
// break circular dep, one of those days again...
|
||||||
initialState,
|
getPluginKey(undefined, {serial: this.serial}, plugin.id),
|
||||||
),
|
initialState,
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to start device plugin '${plugin.id}': `, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user