Core: clarify error message when reading an `APContainer` (#2887)

This commit is contained in:
Doug Hoskisson 2024-03-03 11:09:06 -08:00 committed by GitHub
parent 519dffdb73
commit 4e31e51d7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -41,6 +41,13 @@ class AutoPatchRegister(abc.ABCMeta):
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
@ -89,7 +96,15 @@ class APContainer:
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: