-
Notifications
You must be signed in to change notification settings - Fork 534
Open
Description
When running detect-secrets scan --only-allowlisted on a directory containing empty files (for instance a tracked and empty __init__.py), a ValueError is raised:
Traceback (most recent call last):
File ".venv/bin/detect-secrets", line 10, in <module>
sys.exit(main())
~~~~^^
File ".venv/lib/python3.13/site-packages/detect_secrets/main.py", line 30, in main
handle_scan_action(args)
~~~~~~~~~~~~~~~~~~^^^^^^
File ".venv/lib/python3.13/site-packages/detect_secrets/main.py", line 64, in handle_scan_action
for secret in scan_for_allowlisted_secrets_in_file(filename):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/detect_secrets/core/scan.py", line 204, in scan_for_allowlisted_secrets_in_file
yield from _scan_for_allowlisted_secrets_in_lines(enumerate(lines, start=1), filename)
File ".venv/lib/python3.13/site-packages/detect_secrets/core/scan.py", line 229, in _scan_for_allowlisted_secrets_in_lines
line_numbers, lines = zip(*lines)
^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 0)
This is because the provided iterator lines is empty.
A simple way to fix this would be to handle the exception in scan_for_allowlisted_secrets_in_file with:
try:
for lines in _get_lines_from_file(filename):
yield from _scan_for_allowlisted_secrets_in_lines(enumerate(lines, start=1), filename)
break
except IOError:
log.warning(f'Unable to open file: {filename}')
return
except ValueError:
log.warning(f"Unable to scan file: {filename}. Ignore if it is an empty file.")
returnMetadata
Metadata
Assignees
Labels
No labels