Skip to content

Commit

Permalink
Throw a better error when parsing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanatosGit committed Oct 11, 2024
1 parent 29cf504 commit a3fd1a3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/mercury_engine_data_structures/formats/rom3ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Check warning on line 213 in src/mercury_engine_data_structures/formats/rom3ds.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/rom3ds.py#L213

Added line #L213 was not covered by tests
# 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.")

Check warning on line 216 in src/mercury_engine_data_structures/formats/rom3ds.py

View check run for this annotation

Codecov / codecov/patch

src/mercury_engine_data_structures/formats/rom3ds.py#L215-L216

Added lines #L215 - L216 were not covered by tests
self.read_rom_fs()

def get_title_id(self) -> str:
Expand Down

0 comments on commit a3fd1a3

Please sign in to comment.