41 lines
1.3 kB
1"""Exceptions raised on purpose by the fly-in simulator."""
2
3
4class FlyInError(Exception):
5 """Base for every error this program raises on purpose."""
6
7
8class ParserError(FlyInError):
9 """A map file line that violates the format."""
10
11 def __init__(self, line_no: int, line: str, reason: str) -> None:
12 """Record where the map file went wrong.
13
14 Args:
15 line_no: 1-based number of the offending line.
16 line: Raw text of that line, as read from the file.
17 reason: Human-readable explanation of the violation.
18 """
19 self.line_no = line_no
20 self.line = line
21 self.reason = reason
22 super().__init__(f"line {line_no}: {reason}\n {line}")
23
24
25class SimulationError(FlyInError):
26 """A schedule that breaks a rule of the simulation.
27
28 Unlike a parser error this blames the program, not the map: the
29 solver produced a run the rules forbid.
30 """
31
32 def __init__(self, turn: int, reason: str) -> None:
33 """Record which turn of the replay went wrong.
34
35 Args:
36 turn: 1-based number of the turn being replayed.
37 reason: Human-readable explanation of the violation.
38 """
39 self.turn = turn
40 self.reason = reason
41 super().__init__(f"internal: turn {turn}: {reason}")