Skip to content

Commit 6da6055

Browse files
authored
Move exception handling of zipfile exception up on function call
1 parent 7eaf1c2 commit 6da6055

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

openandroidinstaller/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def retrieve_image_metadata(image_path: str) -> dict:
8484
].decode("utf-8")
8585
logger.info(f"Metadata retrieved from image {image_path.split('/')[-1]}.")
8686
return metadata_dict
87-
except zipfile.BadZipFile:
87+
except zipfile.BadZipFile as e:
8888
logger.error("Selected image is not a zip file.")
89-
return dict
89+
raise e
9090
except (FileNotFoundError, KeyError):
9191
logger.error(
9292
f"Metadata file {metapath} not found in {image_path.split('/')[-1]}."
@@ -132,8 +132,8 @@ def image_works_with_device(
132132
Returns:
133133
CheckResult object containing the compatibility status and a message.
134134
"""
135-
metadata = retrieve_image_metadata(image_path)
136135
try:
136+
metadata = retrieve_image_metadata(image_path)
137137
supported_devices = metadata["pre-device"].split(",")
138138
logger.info(f"Image works with the following device(s): {supported_devices}")
139139
if any(code in supported_devices for code in supported_device_codes):
@@ -148,6 +148,11 @@ def image_works_with_device(
148148
CompatibilityStatus.INCOMPATIBLE,
149149
f"Image file {image_path.split('/')[-1]} is not supported by device code.",
150150
)
151+
except zipfile.BadZipFile:
152+
return CheckResult(
153+
CompatibilityStatus.INCOMPATIBLE,
154+
f"Selected image {image_path.split('/')[-1]} is not a zip file.",
155+
)
151156
except KeyError:
152157
logger.error(
153158
f"Could not determine supported devices for {image_path.split('/')[-1]}."

0 commit comments

Comments
 (0)