Skip to content

Fix exit code for invalid scan targets (#1326)#1402

Open
soh2970 wants to merge 3 commits intoPyCQA:mainfrom
soh2970:fix-exit-code-1326
Open

Fix exit code for invalid scan targets (#1326)#1402
soh2970 wants to merge 3 commits intoPyCQA:mainfrom
soh2970:fix-exit-code-1326

Conversation

@soh2970
Copy link
Copy Markdown

@soh2970 soh2970 commented Apr 28, 2026

Fixes #1326

Bandit previously returned exit code 0 when scan targets were invalid (ie. nonexistent directories), even though files were skipped due to errors. This could cause silent failures in CI/CD pipelines.

This change updates the CLI exit logic to return a non zero exit code when scan targets are invalid.

Tests were updated to reflect the corrected behavior, and a functional test was adjusted to expect a non zero exit code for nonexistent paths.

Behavior after fix:

  • Invalid scan targets → exit 1
  • Security findings → exit 1 (unless --exit-zero is set)
  • Clean scan → exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should exit with non-zero code when scanning fails

1 participant