From 63f35128298e57245ccee053f6ac5c2f14b59293 Mon Sep 17 00:00:00 2001 From: qwint Date: Mon, 8 Sep 2025 04:11:46 -0500 Subject: [PATCH] Core: adds a custom KeyError for invalid item names (#4223) * adds a custom KeyError for raising on world.create_item() if the passed in name is invalid * Update __init__.py --------- Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> --- worlds/AutoWorld.py | 4 ++++ worlds/generic/__init__.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index 9233f3d2..676171b7 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -22,6 +22,10 @@ if TYPE_CHECKING: perf_logger = logging.getLogger("performance") +class InvalidItemError(KeyError): + pass + + class AutoWorldRegister(type): world_types: Dict[str, Type[World]] = {} __file__: str diff --git a/worlds/generic/__init__.py b/worlds/generic/__init__.py index 29f808b2..fa53f31f 100644 --- a/worlds/generic/__init__.py +++ b/worlds/generic/__init__.py @@ -3,7 +3,7 @@ import logging from BaseClasses import Item, Tutorial, ItemClassification -from ..AutoWorld import World, WebWorld +from ..AutoWorld import InvalidItemError, World, WebWorld from NetUtils import SlotType @@ -47,7 +47,7 @@ class GenericWorld(World): def create_item(self, name: str) -> Item: if name == "Nothing": return Item(name, ItemClassification.filler, -1, self.player) - raise KeyError(name) + raise InvalidItemError(name) class PlandoItem(NamedTuple):