From a9fe38107670eded3d4f542c122a9346cb7a644a Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Fri, 9 Sep 2022 06:30:04 -0700 Subject: [PATCH] Add more detailed errors for assertConnected Differential Revision: D39383946 fbshipit-source-id: e11a29c77c5abe7f3fee5e979c596efd31ef4ec2 --- .../src/__tests__/test-utils.node.tsx | 4 ++- desktop/flipper-plugin/src/plugin/Plugin.tsx | 28 +++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx b/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx index b3ab3c7d1..6e5f6f667 100644 --- a/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx +++ b/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx @@ -166,7 +166,9 @@ test('a plugin cannot send messages after being disconnected', async () => { await instance.getCurrentState(); } catch (e) { threw = true; // for some weird reason expect(async () => instance.getCurrentState()).toThrow(...) doesn't work today... - expect(e).toMatchInlineSnapshot(`[Error: Plugin is not connected]`); + expect(e).toMatchInlineSnapshot( + `[Error: SandyPluginInstance.assertConnected -> plugin is not connected]`, + ); } expect(threw).toBeTruthy(); }); diff --git a/desktop/flipper-plugin/src/plugin/Plugin.tsx b/desktop/flipper-plugin/src/plugin/Plugin.tsx index aa8aa4d44..c7fd847f5 100644 --- a/desktop/flipper-plugin/src/plugin/Plugin.tsx +++ b/desktop/flipper-plugin/src/plugin/Plugin.tsx @@ -292,14 +292,26 @@ export class SandyPluginInstance extends BasePluginInstance { private assertConnected() { this.assertNotDestroyed(); - if ( - // This is a better-safe-than-sorry; just the first condition should suffice - !this.connected.get() || - !this.realClient.connected.get() || - !this.device.isConnected || - this.device.isArchived - ) { - throw new Error('Plugin is not connected'); + // This is a better-safe-than-sorry; just the first condition should suffice + if (!this.connected.get()) { + throw new Error( + 'SandyPluginInstance.assertConnected -> plugin is not connected', + ); + } + if (!this.realClient.connected.get()) { + throw new Error( + 'SandyPluginInstance.assertConnected -> realClient is not connected', + ); + } + if (!this.device.isConnected) { + throw new Error( + 'SandyPluginInstance.assertConnected -> device is not connected', + ); + } + if (this.device.isArchived) { + throw new Error( + 'SandyPluginInstance.assertConnected -> device is archived', + ); } } }