Make sure flipper server initialization errors are propagated properly

Summary:
This diff makes sure that errors are propagated similarly in flipper desktop and browser version, and that they are shown in either case.

Since in the browser version, the UI loads after the error happened, we'll store the error so that any client connecting in the future will read and report it.

Also added a `--failFast` flag to flipper-server, so that the process exits immediately if misconfigured, which is convenient in CI use cases and such

Reviewed By: nikoant

Differential Revision: D33348922

fbshipit-source-id: 0f584104f881141fde38da3f0031748415343ea2
This commit is contained in:
Michel Weststrate
2022-01-04 02:56:33 -08:00
committed by Facebook GitHub Bot
parent 8259f92983
commit b6c884f011
13 changed files with 96 additions and 46 deletions

View File

@@ -15,6 +15,7 @@ import {
NoLongerConnectedToClientError,
isTest,
DeviceDescription,
FlipperServerState,
} from 'flipper-common';
import Client from '../Client';
import {notification} from 'antd';
@@ -41,6 +42,8 @@ export function connectFlipperServerToStore(
});
});
server.on('server-state', handleServerStateChange);
server.on('server-error', (err) => {
notification.error({
message: 'Failed to start connection server',
@@ -113,6 +116,13 @@ export function connectFlipperServerToStore(
'Flipper server started and accepting device / client connections',
);
server
.exec('get-server-state')
.then(handleServerStateChange)
.catch((e) => {
console.error(`Failed to get initial server state`, e);
});
// this flow is spawned delibarately from this main flow
waitFor(store, (state) => state.plugins.initialized)
.then(() => server.exec('device-list'))
@@ -173,6 +183,25 @@ function startSideEffects(store: Store, server: FlipperServer) {
};
}
function handleServerStateChange({
state,
error,
}: {
state: FlipperServerState;
error?: string;
}) {
if (state === 'error') {
console.warn(`[conn] Flipper server state -> ${state}`, error);
notification.error({
message: 'Failed to start flipper-server',
description: '' + error,
duration: null,
});
} else {
console.info(`[conn] Flipper server state -> ${state}`);
}
}
function handleDeviceConnected(
server: FlipperServer,
store: Store,