From d4b1351c99f44f4d0444e5d8055572317f52218b Mon Sep 17 00:00:00 2001 From: Mysteryem Date: Thu, 21 Nov 2024 19:43:37 +0000 Subject: [PATCH] Aquaria: Remove BaseException handling from create_item (#4218) * Aquaria: Remove BaseException handling from create_item Catching `BaseException` without re-raising the exception should almost never be done because `BaseException` includes exit exceptions, such as `SystemExit` and `KeyboardInterrupt`. Ideally, the caught exception types should be as narrow as possible to not mask bugs from catching unexpected exceptions. Having narrow exception types can also help indicate to other developers what exceptions are expected to be raisable by the code within the `try` clause. Similarly, the `try` clause should ideally contain the minimum code necessary, to avoid masking bugs in the case that code within the `try` clause that is not expected to raise an exception does so. In this case, the only expected exception that can occur appears to be `item_table[name]` that can raise a `KeyError` when `create_item()` is passed an unexpected `name` argument. So this patch moves the other code out of the `try` clause and changes the caught exception types to only `KeyError`. * Remove try-except The KeyError that would be raised will be propagated as-is rather than raising a new exception in its place. * Remove extra newline The original code did not have this newline, so it has been removed. --- worlds/aquaria/__init__.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/worlds/aquaria/__init__.py b/worlds/aquaria/__init__.py index f79978f2..f620bf6d 100644 --- a/worlds/aquaria/__init__.py +++ b/worlds/aquaria/__init__.py @@ -117,16 +117,13 @@ class AquariaWorld(World): Create an AquariaItem using 'name' as item name. """ result: AquariaItem - try: - data = item_table[name] - classification: ItemClassification = ItemClassification.useful - if data.type == ItemType.JUNK: - classification = ItemClassification.filler - elif data.type == ItemType.PROGRESSION: - classification = ItemClassification.progression - result = AquariaItem(name, classification, data.id, self.player) - except BaseException: - raise Exception('The item ' + name + ' is not valid.') + data = item_table[name] + classification: ItemClassification = ItemClassification.useful + if data.type == ItemType.JUNK: + classification = ItemClassification.filler + elif data.type == ItemType.PROGRESSION: + classification = ItemClassification.progression + result = AquariaItem(name, classification, data.id, self.player) return result