Skip to content

Commit

Permalink
fix: Error output for mismatched options
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Nov 24, 2020
1 parent 3e22db5 commit d79edf6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ async function handleError(args, error) {
if (args.options.debug && !args.options.json) {
const output = vulnsFound ? error.message : error.stack;
console.log(output);
} else if (args.options.json) {
} else if (
args.options.json &&
!(error instanceof UnsupportedOptionCombinationError)
) {
console.log(stripAnsi(error.json || error.stack));
} else {
if (!args.options.quiet) {
Expand Down
28 changes: 26 additions & 2 deletions test/acceptance/cli-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,26 @@ test(
);

test('flags not allowed with --sarif', (t) => {
t.plan(1);
exec(`node ${main} test --sarif --json`, (err, stdout) => {
t.plan(4);
exec(`node ${main} test iac --sarif --json`, (err, stdout) => {
if (err) {
console.log('CLI stdout: ', stdout);
throw err;
}
t.match(
stdout.trim(),
new UnsupportedOptionCombinationError(['test', 'sarif', 'json'])
.userMessage,
'Display unsupported combination error message (iac)',
);
t.equal(
stdout.trim().split('\n').length,
1,
'Error message should not include stacktrace (iac)',
);
});

exec(`node ${main} test container --sarif --json`, (err, stdout) => {
if (err) {
console.log('CLI stdout: ', stdout);
throw err;
Expand All @@ -464,6 +482,12 @@ test('flags not allowed with --sarif', (t) => {
stdout.trim(),
new UnsupportedOptionCombinationError(['test', 'sarif', 'json'])
.userMessage,
'Display unsupported combination error message (container)',
);
t.equal(
stdout.trim().split('\n').length,
1,
'Error message should not include stacktrace (container)',
);
});
});
Expand Down

0 comments on commit d79edf6

Please sign in to comment.