From a82934490ec9ab9ccb566f16f5c5706658736071 Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 14 Jun 2019 05:17:44 -0700 Subject: [PATCH] Fix process exit when error occurs Summary: When running in headless mode, if SIGINT is received, but there's a failure to export the state the process doesn't exit. Repeated SIGINTs do the same thing. This changes it to exit whether the export succeeds or not. Reviewed By: passy Differential Revision: D15806412 fbshipit-source-id: 1f6a5b4ea1cd65dacb201f8a1cd020531b3976e6 --- headless/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/headless/index.js b/headless/index.js index 5224602a1..f484de001 100644 --- a/headless/index.js +++ b/headless/index.js @@ -101,6 +101,12 @@ function outputAndExit(output: string): void { }); } +function errorAndExit(error: string): void { + process.stderr.write(error, () => { + process.exit(1); + }); +} + async function earlyExitActions( userArguments: UserArguments, originalConsole: typeof global.console, @@ -228,13 +234,17 @@ async function startFlipper(userArguments: UserArguments) { .then(payload => { outputAndExit(payload || ''); }) - .catch(console.error); + .catch(e => { + errorAndExit(e.message); + }); } else { exportStore(store) .then(({serializedString}) => { outputAndExit(serializedString); }) - .catch(console.error); + .catch(e => { + errorAndExit(e.message); + }); } }, 10); }