Add more detailed errors for assertConnected
Differential Revision: D39383946 fbshipit-source-id: e11a29c77c5abe7f3fee5e979c596efd31ef4ec2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d2ce30942f
commit
a9fe381076
@@ -166,7 +166,9 @@ test('a plugin cannot send messages after being disconnected', async () => {
|
|||||||
await instance.getCurrentState();
|
await instance.getCurrentState();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
threw = true; // for some weird reason expect(async () => instance.getCurrentState()).toThrow(...) doesn't work today...
|
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();
|
expect(threw).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -292,14 +292,26 @@ export class SandyPluginInstance extends BasePluginInstance {
|
|||||||
|
|
||||||
private assertConnected() {
|
private assertConnected() {
|
||||||
this.assertNotDestroyed();
|
this.assertNotDestroyed();
|
||||||
if (
|
|
||||||
// This is a better-safe-than-sorry; just the first condition should suffice
|
// This is a better-safe-than-sorry; just the first condition should suffice
|
||||||
!this.connected.get() ||
|
if (!this.connected.get()) {
|
||||||
!this.realClient.connected.get() ||
|
throw new Error(
|
||||||
!this.device.isConnected ||
|
'SandyPluginInstance.assertConnected -> plugin is not connected',
|
||||||
this.device.isArchived
|
);
|
||||||
) {
|
}
|
||||||
throw new Error('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',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user