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