From 0e8b8e5ffdc19eedf7e1d1f84f2a42111abc7ba9 Mon Sep 17 00:00:00 2001 From: Bryan Osenbach Date: Thu, 5 Mar 2026 13:49:31 -0500 Subject: [PATCH 1/2] Handle unicode exception while logging details Signed-off-by: Bryan Osenbach --- detect_secrets/core/secrets_collection.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index d3948c647..3b250263a 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., Python 3.13 compatibility) + log.warning( + 'Could not determine if file is binary (%s): %s. Treating as binary.', + filename, + str(e), + ) + file_is_binary = True if not file_is_binary and not suppress_unscannable_file_warnings: log.warning( From 9cfcb8621279cc04fbe7335e74c73a46c0c23109 Mon Sep 17 00:00:00 2001 From: Bryan Osenbach Date: Thu, 5 Mar 2026 14:15:46 -0500 Subject: [PATCH 2/2] Pin chardet version, keep logging, but don't default to file_is_binary = True Signed-off-by: Bryan Osenbach --- detect_secrets/core/secrets_collection.py | 8 ++++---- setup.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index 3b250263a..f1f5d7dd0 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -420,13 +420,13 @@ def _extract_secrets_from_file( try: file_is_binary = is_binary(filename) except Exception as e: - # Handle cases where is_binary() itself fails (e.g., Python 3.13 compatibility) - log.warning( - 'Could not determine if file is binary (%s): %s. Treating as binary.', + # 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), ) - file_is_binary = True + 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': [