diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index d3948c647..f1f5d7dd0 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -416,7 +416,17 @@ def _extract_secrets_from_file( f.seek(0) except UnicodeDecodeError: - file_is_binary = is_binary(filename) + log.warning('UnicodeDecodeError encountered while scanning file: %s', filename) + try: + file_is_binary = is_binary(filename) + except Exception as e: + # Handle cases where is_binary() itself fails (e.g., chardet compatibility issues) + log.error( + 'Could not determine if file is binary (%s): %s', + filename, + str(e), + ) + raise if not file_is_binary and not suppress_unscannable_file_warnings: log.warning( diff --git a/setup.py b/setup.py index c7e4d2858..76b638b81 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ 'packaging', 'tabulate', 'binaryornot', + 'chardet>=3.0.2,<7.0.0', ], extras_require={ 'word_list': [