Skip to content

Fix: ValueError handling for empty files scanning with only-allowlist…#938

Open
Roman-Malinowski wants to merge 2 commits intoYelp:masterfrom
Roman-Malinowski:#936/scan_empty_file_with_only-allowlisted
Open

Fix: ValueError handling for empty files scanning with only-allowlist…#938
Roman-Malinowski wants to merge 2 commits intoYelp:masterfrom
Roman-Malinowski:#936/scan_empty_file_with_only-allowlisted

Conversation

@Roman-Malinowski
Copy link
Copy Markdown

Fixes #936

  • All CI checks are green
  • What kind of change does this PR introduce?

Bug fix: Handling the ValueError when running detect-secrets scan --only-allowlisted in a directory containing empty files

  • What is the current behavior?

A ValueError is raised as described in issue #936

  • What is the new behavior (if this is a feature change)?
    A warning is raised, and the scan continues.

Comment thread detect_secrets/core/scan.py Outdated
Comment on lines +209 to +211
except ValueError:
log.warning(f'Unable to scan file: {filename}. Please ignore if file is empty.')
return
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest checking if lines: above instead - that way we'll be specifically addressing the issue (as opposed to any ValueError exception) and we won't need to execute the line yield from _scan_for_allowlisted_secrets_in_lines(enumerate(lines, start=1), filename) at all

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I added the suggested modifications.

Update scanning logic to check if lines are not empty before scanning for allowlisted secrets.
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.

Scan with -only-allowlisted flag raises a ValueError when checking empty files.

2 participants