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:
parent
859ae87ec9
commit
d4b1351c99
|
@ -117,16 +117,13 @@ class AquariaWorld(World):
|
||||||
Create an AquariaItem using 'name' as item name.
|
Create an AquariaItem using 'name' as item name.
|
||||||
"""
|
"""
|
||||||
result: AquariaItem
|
result: AquariaItem
|
||||||
try:
|
data = item_table[name]
|
||||||
data = item_table[name]
|
classification: ItemClassification = ItemClassification.useful
|
||||||
classification: ItemClassification = ItemClassification.useful
|
if data.type == ItemType.JUNK:
|
||||||
if data.type == ItemType.JUNK:
|
classification = ItemClassification.filler
|
||||||
classification = ItemClassification.filler
|
elif data.type == ItemType.PROGRESSION:
|
||||||
elif data.type == ItemType.PROGRESSION:
|
classification = ItemClassification.progression
|
||||||
classification = ItemClassification.progression
|
result = AquariaItem(name, classification, data.id, self.player)
|
||||||
result = AquariaItem(name, classification, data.id, self.player)
|
|
||||||
except BaseException:
|
|
||||||
raise Exception('The item ' + name + ' is not valid.')
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue