Add more detailed errors for assertConnected

Differential Revision: D39383946

fbshipit-source-id: e11a29c77c5abe7f3fee5e979c596efd31ef4ec2
This commit is contained in:
Andrey Goncharov
2022-09-09 06:30:04 -07:00
committed by Facebook GitHub Bot
parent d2ce30942f
commit a9fe381076
2 changed files with 23 additions and 9 deletions

View File

@@ -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();
});

View File

@@ -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');
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',
);
}
}
}