Change "not found" style errors from RuntimeError (misc error) to KeyError (value not found for a given search key)

This commit is contained in:
Fabian Dill 2020-09-13 17:07:46 +02:00
parent c11fe9cb51
commit d32bfb7bdf
3 changed files with 13 additions and 13 deletions

View File

@ -176,7 +176,7 @@ class World(object):
assert not region.world # this should only happen before initialization
self._region_cache[player][regionname] = region
return region
raise RuntimeError('No such region %s for player %d' % (regionname, player))
raise KeyError('No such region %s for player %d' % (regionname, player))
def get_entrance(self, entrance: str, player: int) -> Entrance:
try:
@ -197,7 +197,7 @@ class World(object):
self._entrance_cache[(entrance, player)] = exit
return exit
raise RuntimeError('No such entrance %s for player %d' % (entrance, player))
raise KeyError('No such entrance %s for player %d' % (entrance, player))
def get_location(self, location: str, player: int) -> Location:
try:
@ -218,13 +218,13 @@ class World(object):
self._location_cache[(location, player)] = r_location
return r_location
raise RuntimeError('No such location %s for player %d' % (location, player))
raise KeyError('No such location %s for player %d' % (location, player))
def get_dungeon(self, dungeonname: str, player: int) -> Dungeon:
for dungeon in self.dungeons:
if dungeon.name == dungeonname and dungeon.player == player:
return dungeon
raise RuntimeError('No such dungeon %s for player %d' % (dungeonname, player))
raise KeyError('No such dungeon %s for player %d' % (dungeonname, player))
def _debug_get_dungeon(self, dungeonname: str, player: int) -> Dungeon:
if type(dungeonname) != str:
@ -232,7 +232,7 @@ class World(object):
for dungeon in self.dungeons:
if dungeon.name == dungeonname and dungeon.player == player:
return dungeon
raise RuntimeError('No such dungeon %s for player %d' % (dungeonname, player))
raise KeyError('No such dungeon %s for player %d' % (dungeonname, player))
def get_all_state(self, keys=False) -> CollectionState:
ret = CollectionState(self)

View File

@ -644,7 +644,7 @@ def link_entrances(world, player):
candidate = cave
break
if candidate is None:
raise RuntimeError('No suitable cave.')
raise KeyError('No suitable cave.')
cavelist.remove(candidate)
return candidate
@ -659,7 +659,7 @@ def link_entrances(world, player):
try:
cave = extract_reachable_exit(primary)
except RuntimeError:
except KeyError:
cave = extract_reachable_exit(secondary)
exit = cave[-1]
@ -863,7 +863,7 @@ def link_entrances(world, player):
candidate = cave
break
if candidate is None:
raise RuntimeError('No suitable cave.')
raise KeyError('No suitable cave.')
cavelist.remove(candidate)
return candidate
@ -998,7 +998,7 @@ def link_entrances(world, player):
candidate = cave
break
if candidate is None:
raise RuntimeError('No suitable cave.')
raise KeyError('No suitable cave.')
cavelist.remove(candidate)
return candidate
@ -1709,7 +1709,7 @@ def link_inverted_entrances(world, player):
candidate = cave
break
if candidate is None:
raise RuntimeError('No suitable cave.')
raise KeyError('No suitable cave.')
cavelist.remove(candidate)
return candidate
@ -1792,7 +1792,7 @@ def connect_entrance(world, entrancename: str, exitname: str, player: int):
try:
region = world.get_region(exitname, player)
exit = None
except RuntimeError:
except KeyError:
exit = world.get_entrance(exitname, player)
region = exit.parent_region
@ -1974,7 +1974,7 @@ def connect_mandatory_exits(world, entrances, caves, must_be_exits, player):
break
if cave is None:
raise RuntimeError('No more caves left. Should not happen!')
raise KeyError('No more caves left. Should not happen!')
# all caves are sorted so that the last exit is always reachable
connect_two_way(world, exit, cave[-1], player)

View File

@ -1939,4 +1939,4 @@ class TextTable(object):
text['ganon_phase_3_silvers'] = CompressedTextMapper.convert("Oh no! Silver! My one true weakness!")
text['murahdahla'] = CompressedTextMapper.convert("Hello @. I\nam Murahdahla, brother of\nSahasrahla and Aginah. Behold the power of\ninvisibility.\n{PAUSE3}\n… … …\nWait! you can see me? I knew I should have\nhidden in a hollow tree.")
text['end_pad_data'] = bytearray([0xfb])
text['terminator'] = bytearray([0xFF, 0xFF])
text['terminator'] = bytearray([0xFF, 0xFF])