From a3fd1a315b3b14328f6c225d8e37666cda4cbf60 Mon Sep 17 00:00:00 2001 From: Thanatos Date: Fri, 11 Oct 2024 14:53:57 +0200 Subject: [PATCH] Throw a better error when parsing fails --- .../formats/rom3ds.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mercury_engine_data_structures/formats/rom3ds.py b/src/mercury_engine_data_structures/formats/rom3ds.py index 22bd077..fe6e0a9 100644 --- a/src/mercury_engine_data_structures/formats/rom3ds.py +++ b/src/mercury_engine_data_structures/formats/rom3ds.py @@ -202,14 +202,18 @@ class Rom3DS: def __init__(self, file_name: str, file_stream: BufferedReader): self.file_name_to_entry = {} self.file_stream = file_stream - if file_name.lower().endswith("cia"): - self.raw = AddCia.parse_stream(file_stream) - elif file_name.lower().endswith("3ds"): - self.raw = Add3ds.parse_stream(file_stream) - elif file_name.lower().endswith("app") or file_name.lower().endswith("cxi"): - self.raw = AddCxi.parse_stream(file_stream) - else: - raise ValueError('Input does not end with ".cia" or ".3ds') + try: + if file_name.lower().endswith("cia"): + self.raw = AddCia.parse_stream(file_stream) + elif file_name.lower().endswith("3ds"): + self.raw = Add3ds.parse_stream(file_stream) + elif file_name.lower().endswith("app") or file_name.lower().endswith("cxi"): + self.raw = AddCxi.parse_stream(file_stream) + else: + raise ValueError('Input does not end with ".cia" or ".3ds') + # encrypted files should throw a ConstError because the ".code" string is encrypted and parsing fails + except construct.core.ConstError: + raise ValueError("Rom file could not be parsed. Make sure that you use a decrypted supported file format.") self.read_rom_fs() def get_title_id(self) -> str: