This repository was archived by the owner on May 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
114 lines (85 loc) · 2.78 KB
/
exceptions.py
File metadata and controls
114 lines (85 loc) · 2.78 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""Custom exception classes for KaivosAI.
Provides specific exception types for different error scenarios,
enabling better error handling and more informative error messages.
Exception Hierarchy:
GameError (base)
├── MapError - Map/world operations
├── DatabaseError - Database operations
├── CommandError - CLI command parsing/execution
├── RobotError - Robot operations
└── ValidationError - Input validation
"""
class GameError(Exception):
"""Base exception for all KaivosAI game errors.
All custom exceptions in the game inherit from this class,
allowing broad exception catching when needed.
Args:
message: Error description
details: Optional additional context (dict, str, etc.)
Attributes:
message: Error description string
details: Additional error context
"""
def __init__(self, message: str, details=None):
self.message = message
self.details = details
super().__init__(self.message)
def __str__(self):
if self.details:
return f"{self.message} (Details: {self.details})"
return self.message
class MapError(GameError):
"""Exception for map-related operations.
Raised when:
- Object not found at position
- Invalid position coordinates
- Collision detection fails
- Pathfinding errors
Example:
>>> raise MapError("Position (5,5) out of bounds", details={"pos": (5,5)})
"""
pass
class DatabaseError(GameError):
"""Exception for database operations.
Raised when:
- Connection failures
- Query execution errors
- Data integrity violations
- Migration failures
Example:
>>> raise DatabaseError("Failed to persist object", details={"id": 42})
"""
pass
class CommandError(GameError):
"""Exception for CLI command processing.
Raised when:
- Invalid command syntax
- Missing required parameters
- Parameter parsing failures
- Command execution errors
Example:
>>> raise CommandError("Invalid robot ID", details={"input": "abc"})
"""
pass
class RobotError(GameError):
"""Exception for robot operations.
Raised when:
- Robot not found
- Invalid robot state
- Program execution errors
- Movement/pathfinding failures
Example:
>>> raise RobotError("Robot inventory full", details={"capacity": 5})
"""
pass
class ValidationError(GameError):
"""Exception for input validation failures.
Raised when:
- Invalid coordinates
- Out of range values
- Type mismatches
- Constraint violations
Example:
>>> raise ValidationError("Coordinate out of range", details={"x": -1})
"""
pass