Skip to content

Commit

Permalink
Core: clarify error message when reading an APContainer (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
beauxq authored Mar 3, 2024
1 parent 519dffd commit 4e31e51
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion worlds/Files.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def get_handler(file: str) -> Optional[AutoPatchRegister]:
current_patch_version: int = 5


class InvalidDataError(Exception):
"""
Since games can override `read_contents` in APContainer,
this is to report problems in that process.
"""


class APContainer:
"""A zipfile containing at least archipelago.json"""
version: int = current_patch_version
Expand Down Expand Up @@ -89,7 +96,15 @@ def read(self, file: Optional[Union[str, BinaryIO]] = None) -> None:
with zipfile.ZipFile(zip_file, "r") as zf:
if file:
self.path = zf.filename
self.read_contents(zf)
try:
self.read_contents(zf)
except Exception as e:
message = ""
if len(e.args):
arg0 = e.args[0]
if isinstance(e.args[0], str):
message = f"{arg0} - "
raise InvalidDataError(f"{message}This might be the incorrect world version for this file") from e

def read_contents(self, opened_zipfile: zipfile.ZipFile) -> None:
with opened_zipfile.open("archipelago.json", "r") as f:
Expand Down

0 comments on commit 4e31e51

Please sign in to comment.