From fbbd90e9f510d46ac9a561274d2712cd9bd6f0d0 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Thu, 13 Oct 2022 03:14:06 -0700 Subject: [PATCH] Suggest a quick fix for EADDRINUSE Summary: Show users a way to fix Flipper EADDRINUSE on their own without filing a support request CHANGELOG: Better error message for EADDRINUSE Reviewed By: mweststrate Differential Revision: D40338164 fbshipit-source-id: ec0419c78983b55736aa773757775b5302da51e0 --- .../src/dispatcher/flipperServer.tsx | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx b/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx index 48b581acb..fefc9b9b2 100644 --- a/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/flipperServer.tsx @@ -45,27 +45,15 @@ export function connectFlipperServerToStore( server.on('server-state', handleServerStateChange); server.on('server-error', (err) => { - notification.error({ - message: 'Connection error', - description: - err.code === 'EADDRINUSE' ? ( - <> - Couldn't start connection server. Looks like you have multiple - copies of Flipper running or another process is using the same - port(s). As a result devices will not be able to connect to Flipper. -
-
- Please try to kill the offending process by running{' '} - kill $(lsof -ti:PORTNUMBER) and restart flipper. -
-
- {'' + err} - - ) : ( - <>{err.message ?? err} - ), - duration: null, - }); + if (err.code === 'EADDRINUSE') { + handeEADDRINUSE('' + err); + } else { + notification.error({ + message: 'Connection error', + description: <>{err.message ?? err}, + duration: null, + }); + } }); server.on('device-connected', (deviceInfo) => { @@ -189,16 +177,41 @@ function handleServerStateChange({ }) { if (state === 'error') { console.warn(`[conn] Flipper server state -> ${state}`, error); - notification.error({ - message: 'Failed to start flipper-server', - description: '' + error, - duration: null, - }); + if (error?.includes('EADDRINUSE')) { + handeEADDRINUSE(error); + } else { + notification.error({ + message: 'Failed to start flipper-server', + description: '' + error, + duration: null, + }); + } } else { console.info(`[conn] Flipper server state -> ${state}`); } } +function handeEADDRINUSE(errorMessage: string) { + notification.error({ + message: 'Connection error', + description: ( + <> + Couldn't start connection server. Looks like you have multiple copies of + Flipper running or another process is using the same port(s). As a + result devices will not be able to connect to Flipper. +
+
+ Please try to kill the offending process by running{' '} + kill $(lsof -ti:PORTNUMBER) and restart flipper. +
+
+ {errorMessage} + + ), + duration: null, + }); +} + export function handleDeviceConnected( server: FlipperServer, store: Store,