diff --git a/desktop/flipper-common/src/index.tsx b/desktop/flipper-common/src/index.tsx index 3df88f1ca..8d3e4e300 100644 --- a/desktop/flipper-common/src/index.tsx +++ b/desktop/flipper-common/src/index.tsx @@ -34,6 +34,7 @@ export { CancelledPromiseError, UserUnauthorizedError, UserNotSignedInError, + NoLongerConnectedToClientError, isConnectivityOrAuthError, isError, isAuthError, diff --git a/desktop/flipper-common/src/utils/errors.tsx b/desktop/flipper-common/src/utils/errors.tsx index 733240e4b..71b87abc9 100644 --- a/desktop/flipper-common/src/utils/errors.tsx +++ b/desktop/flipper-common/src/utils/errors.tsx @@ -60,6 +60,14 @@ export class UserNotSignedInError extends Error { name: 'UserNotSignedInError'; } +export class NoLongerConnectedToClientError extends Error { + constructor(msg: string = 'No longer connected to client.') { + super(msg); + this.name = 'NoLongerConnectedToClientError'; + } + name: 'NoLongerConnectedToClientError'; +} + declare global { interface Error { interaction?: unknown; diff --git a/desktop/flipper-ui-core/src/Client.tsx b/desktop/flipper-ui-core/src/Client.tsx index a95c8b214..6f0033c0d 100644 --- a/desktop/flipper-ui-core/src/Client.tsx +++ b/desktop/flipper-ui-core/src/Client.tsx @@ -15,7 +15,10 @@ import BaseDevice from './devices/BaseDevice'; import {Logger} from 'flipper-common'; import {Store} from './reducers/index'; import {performance} from 'perf_hooks'; -import {reportPluginFailures} from 'flipper-common'; +import { + reportPluginFailures, + NoLongerConnectedToClientError, +} from 'flipper-common'; import {default as isProduction} from './utils/isProduction'; import {EventEmitter} from 'events'; import invariant from 'invariant'; @@ -509,7 +512,7 @@ export default class Client extends EventEmitter { key: 'appnotconnectedwarning', duration: 0.5, }); - reject(new Error('Not connected to client')); + reject(new NoLongerConnectedToClientError()); return; } if (!fromPlugin || this.isAcceptingMessagesFromPlugin(plugin)) { diff --git a/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx b/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx index b42f70ed4..ac7d493ce 100644 --- a/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx @@ -9,7 +9,11 @@ import React from 'react'; import {State, Store} from '../reducers/index'; -import {FlipperServer, Logger} from 'flipper-common'; +import { + FlipperServer, + Logger, + NoLongerConnectedToClientError, +} from 'flipper-common'; import {FlipperServerImpl} from 'flipper-server-core'; import {selectClient} from '../reducers/connections'; import Client from '../Client'; @@ -245,13 +249,24 @@ export async function handleClientConnected( type: 'NEW_CLIENT', payload: client, }); - - await timeout( - 30 * 1000, - client.init(), - `[conn] Failed to initialize client ${query.app} on ${query.device_id} in a timely manner`, - ); - console.log(`[conn] ${query.app} on ${query.device_id} connected and ready.`); + try { + await timeout( + 30 * 1000, + client.init(), + `[conn] Failed to initialize client ${query.app} on ${query.device_id} in a timely manner`, + ); + console.log( + `[conn] ${query.app} on ${query.device_id} connected and ready.`, + ); + } catch (e) { + if (e instanceof NoLongerConnectedToClientError) { + console.warn( + `[conn] Client ${query.app} on ${query.device_id} disconnected while initialising`, + ); + return; + } + throw e; + } } function getDeviceBySerial(