Skip to content

Commit

Permalink
fix: exit code when IaC scans are empty
Browse files Browse the repository at this point in the history
According to
https://support.snyk.io/hc/en-us/articles/360003812578#UUID-c88e66cf-431c-9ab1-d388-a8f82991c6e0,
the Snyk CLI should return 3 when there were no supported files in a
scan. This allows user to distinguish this situation from a complete
scan, and from when errors encountered during the scan.

We were actually returning 2, which is also returned when errors are
encountered during a scan.
  • Loading branch information
Craig Furman committed Sep 13, 2021
1 parent c3e774d commit c3d36d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
CustomError,
NoSupportedSastFiles,
} from '../lib/errors';
import { IaCErrorCodes } from './commands/test/iac-local-execution/types';
import stripAnsi from 'strip-ansi';
import { ExcludeFlagInvalidInputError } from '../lib/errors/exclude-flag-invalid-input';
import { modeValidation } from './modes';
Expand Down Expand Up @@ -96,8 +97,9 @@ async function handleError(args, error) {
'Could not detect supported target files in',
);
const noSupportedSastFiles = error instanceof NoSupportedSastFiles;
const noSupportedIaCFiles = error.code === IaCErrorCodes.NoFilesToScanError;
const noSupportedProjectsDetected =
noSupportedManifestsFound || noSupportedSastFiles;
noSupportedManifestsFound || noSupportedSastFiles || noSupportedIaCFiles;

if (noSupportedProjectsDetected) {
exitCode = EXIT_CODES.NO_SUPPORTED_PROJECTS_DETECTED;
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/spec/iac/snyk_test_local_exec_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Describe "Snyk iac local test command"

It "ignores files with no recognised config types"
When run snyk iac test ../fixtures/iac/kubernetes/pod-invalid.yaml
The status should equal 2
The status should equal 3
The output should include "Could not find any valid infrastructure as code files."
End

Expand Down

0 comments on commit c3d36d5

Please sign in to comment.