Skip to content

Commit

Permalink
fix: respect exit codes for unmanaged
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Ekelund committed May 11, 2023
1 parent 7e49fec commit cb6be2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"rimraf": "^2.6.3",
"semver": "^6.0.0",
"snyk-config": "4.0.0",
"snyk-cpp-plugin": "2.22.1",
"snyk-cpp-plugin": "2.22.2",
"snyk-docker-plugin": "6.3.4",
"snyk-go-plugin": "1.21.0",
"snyk-gradle-plugin": "3.26.4",
Expand Down
35 changes: 20 additions & 15 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,28 @@ async function handleError(args, error) {
let command = 'bad-command';
let exitCode = EXIT_CODES.ERROR;

const noSupportedManifestsFound = error.message?.includes(
'Could not detect supported target files in',
);
const noSupportedSastFiles = error instanceof NoSupportedSastFiles;
const noSupportedIaCFiles = error.code === IaCErrorCodes.NoFilesToScanError;
const noSupportedProjectsDetected =
noSupportedManifestsFound || noSupportedSastFiles || noSupportedIaCFiles;
const vulnsFound = error.code === 'VULNS';

if (noSupportedProjectsDetected) {
exitCode = EXIT_CODES.NO_SUPPORTED_PROJECTS_DETECTED;
}
if (args.command === 'test' && args.options?.unmanaged) {
exitCode = vulnsFound ? EXIT_CODES.VULNS_FOUND : error.code;
} else {
const noSupportedManifestsFound = error.message?.includes(
'Could not detect supported target files in',
);
const noSupportedSastFiles = error instanceof NoSupportedSastFiles;
const noSupportedIaCFiles = error.code === IaCErrorCodes.NoFilesToScanError;
const noSupportedProjectsDetected =
noSupportedManifestsFound || noSupportedSastFiles || noSupportedIaCFiles;

const vulnsFound = error.code === 'VULNS';
if (vulnsFound) {
// this isn't a bad command, so we won't record it as such
command = args.command;
exitCode = EXIT_CODES.VULNS_FOUND;
if (noSupportedProjectsDetected) {
exitCode = EXIT_CODES.NO_SUPPORTED_PROJECTS_DETECTED;
}

if (vulnsFound) {
// this isn't a bad command, so we won't record it as such
command = args.command;
exitCode = EXIT_CODES.VULNS_FOUND;
}
}

if (args.options.debug && !args.options.json) {
Expand Down

0 comments on commit cb6be2e

Please sign in to comment.