From c236307c7837dcd4bb1d058eef9f4531b633115b Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Mon, 10 Aug 2020 10:22:03 +0200 Subject: [PATCH] chore(pacmak): improve error messaging (#1817) When a shelled-out process fails (either on a non-0 status, or killed by a signal), the error message did not include the command that just failed, causing ambiguity with respects to what happened. Additionally, the output included STDOUT and STDERR concatenated (in this order) without any way to distinguishe which is which... This adds a prefix string to each line of those to denote whether STDOUT or STDERR. --- .eslintrc.yaml | 3 +++ packages/jsii-pacmak/lib/util.ts | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .eslintrc.yaml diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 0000000000..13d919e42c --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,3 @@ +--- +extends: ./eslint-config.yaml +root: true diff --git a/packages/jsii-pacmak/lib/util.ts b/packages/jsii-pacmak/lib/util.ts index 2d85818cb8..f97c115c38 100644 --- a/packages/jsii-pacmak/lib/util.ts +++ b/packages/jsii-pacmak/lib/util.ts @@ -73,9 +73,20 @@ export async function shell( const command = `${cmd} ${args.join(' ')}`; return ko( new Error( - `Command exited with ${reason}:\n- Command: ${command}\n- STDOUT:\n${out}\n- STDERR:\n${err}`, + [ + `Command (${command}) failed with ${reason}:`, + prefix(out, '#STDOUT> '), + prefix(err, '#STDERR> '), + ].join('\n'), ), ); + + function prefix(text: string, add: string): string { + return text + .split('\n') + .map((line) => `${add}${line}`) + .join('\n'); + } }); }); }