Skip to content

Commit

Permalink
chore(pacmak): improve error messaging (#1817)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RomainMuller authored Aug 10, 2020
1 parent 71a4d8e commit c236307
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
extends: ./eslint-config.yaml
root: true
13 changes: 12 additions & 1 deletion packages/jsii-pacmak/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});
}
Expand Down

0 comments on commit c236307

Please sign in to comment.