Skip to content

Commit

Permalink
fix: exit code 1 if orgs:data errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Mar 3, 2022
1 parent 6643526 commit 228332e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cmds/orgs:data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as debugLib from 'debug';
import * as yargs from 'yargs';
const debug = debugLib('snyk:orgs-data-script');

import { getLoggingPath } from '../lib/get-logging-path';
Expand Down Expand Up @@ -75,9 +76,9 @@ export async function handler(argv: {

console.log(orgsMessage);
} catch (e) {
const errorMessage = `ERROR! Failed to generate data. Try running with \`DEBUG=snyk* <command> for more info\`.\nERROR: ${e.message}`;
debug('Failed to generate data.\n' + e);
console.error(
`ERROR! Failed to generate data. Try running with \`DEBUG=snyk* <command> for more info\`.\nERROR: ${e}`,
);
console.error(errorMessage);
yargs.exit(1, new Error(errorMessage));
}
}
21 changes: 21 additions & 0 deletions test/system/orgs:data/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,25 @@ describe('General `snyk-api-import orgs:data <...>`', () => {
done();
});
});
it('Shows error when token is invalid', (done) => {
const groupId = 'hello';
exec(
`node ${main} orgs:data --source=github --groupId=${groupId}`,
{
env: {
PATH: process.env.PATH,
GITHUB_TOKEN: 'invalid',
SNYK_LOG_PATH: __dirname,
},
},
(err, stdout, stderr) => {
expect(err!.message).toMatch('ERROR: Bad credentials');
expect(stdout).toEqual('');
expect(stderr).toMatch('ERROR: Bad credentials');
},
).on('exit', (code) => {
expect(code).toEqual(1);
done();
});
});
});

0 comments on commit 228332e

Please sign in to comment.