Fix: Handle ValueError when converting plane names

This commit is contained in:
LmeSzinc 2023-10-02 17:13:01 +08:00
parent 2e4ea37ca6
commit 80429efe72

View File

@ -67,14 +67,14 @@ class MapPlane(Keyword):
try: try:
_ = self.floors[floor - 1] _ = self.floors[floor - 1]
return floor return floor
except IndexError: except (IndexError, ValueError):
raise ScriptError(f'Plane {self} does not have floor index {floor}') raise ScriptError(f'Plane {self} does not have floor index {floor}')
elif isinstance(floor, str): elif isinstance(floor, str):
# Convert to floor index # Convert to floor index
floor = floor.upper() floor = floor.upper()
try: try:
return self.floors.index(floor) + 1 return self.floors.index(floor) + 1
except IndexError: except (IndexError, ValueError):
raise ScriptError(f'Plane {self} does not have floor name {floor}') raise ScriptError(f'Plane {self} does not have floor name {floor}')
else: else:
raise ScriptError(f'Plane {self} does not have floor {floor}') raise ScriptError(f'Plane {self} does not have floor {floor}')
@ -95,7 +95,7 @@ class MapPlane(Keyword):
# Convert to floor index # Convert to floor index
try: try:
return self.floors[floor - 1] return self.floors[floor - 1]
except IndexError: except (IndexError, ValueError):
raise ScriptError(f'Plane {self} does not have floor index {floor}') raise ScriptError(f'Plane {self} does not have floor index {floor}')
elif isinstance(floor, str): elif isinstance(floor, str):
# Check exist # Check exist
@ -103,7 +103,7 @@ class MapPlane(Keyword):
try: try:
_ = self.floors.index(floor) + 1 _ = self.floors.index(floor) + 1
return floor return floor
except IndexError: except (IndexError, ValueError):
raise ScriptError(f'Plane {self} does not have floor name {floor}') raise ScriptError(f'Plane {self} does not have floor name {floor}')
else: else:
raise ScriptError(f'Plane {self} does not have floor {floor}') raise ScriptError(f'Plane {self} does not have floor {floor}')