From fd9f0b2483b7b56f156592e06a01bc44e60dd584 Mon Sep 17 00:00:00 2001 From: Mateusz Wielgos Date: Tue, 21 Nov 2017 11:50:36 -0800 Subject: [PATCH] react-native-git-upgrade signal termination Summary: When performing an upgrade using react-native-git-upgrade git can fail with a signal, however, only exit codes are accounted for. Related issue: #12336 In my case, Git fails with a `SIGPIPE` signal - have not figured out why yet, but that's a separate issue. Before, since exit code was not zero, the console would default to the error case, but since no exit code was supplied, the error message was meaningless - `exited with code null`. Now, it errors out with `terminated with signal 'SIGPIPE'`, while still taking account of exit codes. Quoting [nodejs docs](https://nodejs.org/api/child_process.html#child_process_event_exit): > The 'exit' event is emitted after the child process ends. If the process exited, code is the final exit code of the process, otherwise null. If the process terminated due to receipt of a signal, signal is the string name of the signal, otherwise null. One of the two will always be non-null. I would be happy to write a test case for this but I haven't seen any react-native-git-upgrade ones? [CLI] [ENHANCEMENT] [react-native/react-native-git-upgrade] - Git terminated by signal error message Closes https://github.com/facebook/react-native/pull/16822 Differential Revision: D6387451 Pulled By: shergin fbshipit-source-id: 25bf9dabdb5fda70d220bcd5f14c3c92bba8c3d4 --- react-native-git-upgrade/cliEntry.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/react-native-git-upgrade/cliEntry.js b/react-native-git-upgrade/cliEntry.js index 59b271b37bb07f..b65c23733ddf3e 100644 --- a/react-native-git-upgrade/cliEntry.js +++ b/react-native-git-upgrade/cliEntry.js @@ -52,12 +52,18 @@ function exec(command, logOutput) { process.stderr.write(data); }); - child.on('exit', code => { - (code === 0) - ? resolve(stdout) - : reject(new Error(`Command '${command}' exited with code ${code}: + child.on('exit', (code, signal) => { + if (code === 0) { + resolve(stdout); + } else if (code) { + reject(new Error(`Command '${command}' exited with code ${code}: stderr: ${stderr} stdout: ${stdout}`)); + } else { + reject(new Error(`Command '${command}' terminated with signal '${signal}': +stderr: ${stderr} +stdout: ${stdout}`)); + } }); }); }