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.
This commit is contained in:
Mysteryem 2024-11-21 19:43:37 +00:00 committed by GitHub
parent 859ae87ec9
commit d4b1351c99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 10 deletions

View File

@ -117,7 +117,6 @@ 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:
@ -125,8 +124,6 @@ class AquariaWorld(World):
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.')
return result