Skip to content

Commit 02f9a7a

Browse files
committed
Added exception handling for UnicodeDecodeError. fixes issue #1526
Signed-off-by: Aayush Kumar <[email protected]>
1 parent ce4e46a commit 02f9a7a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

scanpipe/pipes/js.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import hashlib
2424
import json
25+
import logging
2526
from contextlib import suppress
2627
from pathlib import Path
2728

@@ -62,6 +63,7 @@
6263
},
6364
}
6465

66+
logger = logging.getLogger(__name__)
6567

6668
def is_source_mapping_in_minified(resource, map_file_name):
6769
"""Return True if a string contains a source mapping in its last 5 lines."""
@@ -89,11 +91,18 @@ def source_content_sha1_list(map_file):
8991

9092
def load_json_from_file(location):
9193
"""Return the deserialized json content from ``location``."""
92-
with open(location) as f:
93-
try:
94+
try:
95+
with open(location) as f:
9496
return json.load(f)
95-
except json.JSONDecodeError:
96-
return
97+
except UnicodeDecodeError as e:
98+
logger.error(f"Failed to decode {location} as JSON: {str(e)}")
99+
return
100+
except json.JSONDecodeError as e:
101+
logger.error(f"Invalid JSON format in {location}: {str(e)}")
102+
return
103+
except Exception as e:
104+
logger.error(f"Unexpected error while reading {location}: {str(e)}")
105+
return
97106

98107

99108
def get_map_sources(map_file):

0 commit comments

Comments
 (0)