* Return the exitCode when possible or else throw an error * @param {*} result * @returns
(result)
| 177 | * @returns |
| 178 | */ |
| 179 | function getExitCode(result) { |
| 180 | // https://nodejs.org/docs/latest-v6.x/api/child_process.html#child_process_event_close |
| 181 | if (typeof result.code === 'number' || typeof result.exitCode === 'number') { |
| 182 | return result.code ?? result.exitCode; |
| 183 | } |
| 184 | |
| 185 | // https://nodejs.org/docs/latest-v6.x/api/errors.html#errors_error_code |
| 186 | // istanbul ignore else |
| 187 | if (typeof result.code === 'string' || typeof result.exitCode === 'string') { |
| 188 | return os.constants.errno[result.code ?? result.exitCode]; |
| 189 | } |
| 190 | |
| 191 | // istanbul ignore next: extremely weird |
| 192 | throw new Error(`Received unexpected exit code value ${JSON.stringify(result.code ?? result.exitCode)}`); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Spawn a command asynchronously, _always_ inheriting stdio. |