From e77cd6f8225e9bb988d107ac1679ad37a1135a96 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 14 Mar 2024 16:07:37 -0700 Subject: [PATCH] Added debug message to describe decode failures discussed in issue 214. Exception handler cathes generic Exception objects, logs a debug message including the culprit filename, and then raises the exception. --- pipreqs/pipreqs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index b969ab4..62fffb5 100644 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -177,8 +177,11 @@ def get_file_extensions(): def read_file_content(file_name: str, encoding="utf-8"): if file_ext_is_allowed(file_name, DEFAULT_EXTENSIONS): - with open(file_name, "r", encoding=encoding) as f: - contents = f.read() + try: + contents = f.read() + except Exception as e: + logging.debug("Encountered exception when attempting to decode: {0}".format(file_name)) + raise e elif file_ext_is_allowed(file_name, [".ipynb"]) and scan_noteboooks: contents = ipynb_2_py(file_name, encoding=encoding) return contents