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
This commit is contained in:
John Knox
2019-06-14 05:17:44 -07:00
committed by Facebook Github Bot
parent 766996b8dd
commit a82934490e

View File

@@ -101,6 +101,12 @@ function outputAndExit(output: string): void {
}); });
} }
function errorAndExit(error: string): void {
process.stderr.write(error, () => {
process.exit(1);
});
}
async function earlyExitActions( async function earlyExitActions(
userArguments: UserArguments, userArguments: UserArguments,
originalConsole: typeof global.console, originalConsole: typeof global.console,
@@ -228,13 +234,17 @@ async function startFlipper(userArguments: UserArguments) {
.then(payload => { .then(payload => {
outputAndExit(payload || ''); outputAndExit(payload || '');
}) })
.catch(console.error); .catch(e => {
errorAndExit(e.message);
});
} else { } else {
exportStore(store) exportStore(store)
.then(({serializedString}) => { .then(({serializedString}) => {
outputAndExit(serializedString); outputAndExit(serializedString);
}) })
.catch(console.error); .catch(e => {
errorAndExit(e.message);
});
} }
}, 10); }, 10);
} }