From 93c41aba84b7a12e1ea12d7bea4db6ac017e1cb1 Mon Sep 17 00:00:00 2001 From: Aria Fallah Date: Tue, 26 Mar 2024 22:58:00 -0700 Subject: [PATCH] Don't crash server if chrome fails to open Summary: ## Context Flipper server was shutting itself down because it couldn't open chrome. This isn't a fatal exception though. ## Changes * Catch the exception and log Differential Revision: D55405348 fbshipit-source-id: edc055ee7e7c67db40a3d83bff0e88e89fe7bd5d --- desktop/flipper-server/src/utils/openUI.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/desktop/flipper-server/src/utils/openUI.tsx b/desktop/flipper-server/src/utils/openUI.tsx index 7a4fcb51185..8c87cb094dd 100644 --- a/desktop/flipper-server/src/utils/openUI.tsx +++ b/desktop/flipper-server/src/utils/openUI.tsx @@ -31,12 +31,21 @@ export async function openUI(preference: UIPreference, port: number) { console.info(`[flipper-server] Go to: ${url.toString()}`); - open(url.toString(), {app: {name: open.apps.chrome}}); - - tracker.track('server-open-ui', { - browser: true, - hasToken: token?.length != 0, - }); + try { + const process = await open(url.toString(), { + app: {name: open.apps.chrome}, + }); + await new Promise((resolve, reject) => { + process.on('spawn', resolve); + process.on('error', reject); + }); + tracker.track('server-open-ui', { + browser: true, + hasToken: token?.length != 0, + }); + } catch (err: unknown) { + console.error('[flipper-server] Failed to open browser', err); + } }; if (preference === UIPreference.Browser) {