-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexceptions.py
45 lines (33 loc) · 1.41 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from typings import Coordinate
class BoundsError(Exception):
"""Exception raised for rover position out of bounds
Attributes:
rover_position -- offending position
plateau_size -- size of the plateau
message -- explanation of the error
"""
def __init__(self, rover_position: Coordinate, plateau_size: Coordinate, message=None) -> None:
super().__init__()
self.rover_position = rover_position
self.plateau_size = plateau_size
self.message = message or f"Rover position {self.rover_position} is out of bounds of {self.plateau_size}-sized plateau"
class CollisionError(Exception):
"""Exception raised for rover position in occupied spot
Attributes:
rover_position -- offending position
message -- explanation of the error
"""
def __init__(self, rover_position: Coordinate, message=None) -> None:
super().__init__()
self.rover_position = rover_position
self.message = message or f"Rover collision in position {self.rover_position}"
class CommandError(Exception):
"""Exception raised for invalid command
Attributes:
command -- offending command
message -- explanation of the error
"""
def __init__(self, command: str, message=None) -> None:
super().__init__()
self.command = command
self.message = message or f"Rover received invalid command {self.command}"