From b69c2a228745dcf030d056313275343798e9ba1d Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Wed, 16 Nov 2022 23:17:33 -0800 Subject: [PATCH] fix: display stderr on command failure --- lib/cli/utils.js | 24 +++++++++++++++--------- src/cli/utils.ts | 26 +++++++++++++++----------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/cli/utils.js b/lib/cli/utils.js index 6d09f627e..4ba00a49d 100644 --- a/lib/cli/utils.js +++ b/lib/cli/utils.js @@ -10,20 +10,26 @@ export async function executeCommand(command, verbose = false) { if (verbose) { signale.info(`Running command: ${command}`); } + let stdout, stderr, code = 0; try { - const { stdout, stderr } = await exec(command); - if (stderr && verbose) { - signale.error(stderr); - } - if (verbose) { - signale.info(`Command output: ${stdout}`); - } - return stdout.trim(); + ({ stdout, stderr } = await exec(command)); } catch (error) { - signale.error(error); + ({ stdout, stderr, code } = error); + } + if (code != 0) { + signale.error(`Command failed: ${command}`); + } + if (stderr && verbose) { + signale.error(`Command stderr: ${stderr}`); + } + if (verbose) { + signale.info(`Command stdout: ${stdout}`); + } + if (code != 0) { process.exit(1); } + return stdout.trim(); } export async function download(url, verbose = false) { await executeCommand(`curl -LOf ${url}`, verbose); diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 6c204dde4..c20eca766 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -18,22 +18,26 @@ export async function executeCommand( signale.info(`Running command: ${command}`); } - try { - const { stdout, stderr } = await exec(command); - + let stdout, stderr, code = 0; + try { + ({ stdout, stderr } = await exec(command)); + } catch (error) { + ({ stdout, stderr, code} = error); + } + if(code != 0) { + signale.error(`Command failed: ${command}`); + } if (stderr && verbose) { - signale.error(stderr); + signale.error(`Command stderr: ${stderr}`); } - if (verbose) { - signale.info(`Command output: ${stdout}`); + signale.info(`Command stdout: ${stdout}`); + } + if(code != 0){ + process.exit(1); } - return stdout.trim(); - } catch (error) { - signale.error(error); - process.exit(1); - } + } export async function download(url: string, verbose = false) {