From 3147813e1f21291115e00715d40db8362c9670f7 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Sat, 11 Feb 2017 02:12:36 +0200 Subject: [PATCH] Make build exit with error code when interrupted (#1496) * Make build exit with error code when interrupted This addresses issue #1493. Current behavior is that `npm run build` exits code 0 without creating a bundle when interrupted. This change makes the build script catch catchable interruptions and exit with the appropriate error code. * Better error messages for kill signals * Don't catch SIGINT Ctrl+C should exit silently, and already produces a non-zero exit code when sent to the console while `npm run build` is running. Exit code 0 is produced if SIGINT is sent directly to the `node build.js` process, but this is unlikely to happen. A SIGINT handler in `build.js` will also be triggered by Ctrl+C in the console, potentially producing unnecessary noise. * Style fix * No changes needed to build.js Problem is coming from the parent process, `react-scripts` * Make react-scripts script handle signals * Clarify context --- bin/react-scripts.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/react-scripts.js b/bin/react-scripts.js index 58381833957..a3ae830f45b 100755 --- a/bin/react-scripts.js +++ b/bin/react-scripts.js @@ -13,6 +13,22 @@ case 'test': [require.resolve('../scripts/' + script)].concat(args), {stdio: 'inherit'} ); + if (result.signal) { + if (result.signal == 'SIGKILL') { + console.log( + 'The build failed because the process exited too early. ' + + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.' + ); + } else if (result.signal == 'SIGTERM') { + console.log( + 'The build failed because the process exited too early. ' + + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.' + ); + } + process.exit(1); + } process.exit(result.status); break; default: