-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_handler.py
More file actions
70 lines (55 loc) · 1.75 KB
/
Copy patherror_handler.py
File metadata and controls
70 lines (55 loc) · 1.75 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
"""
Error Handler Module - Collects and formats errors
"""
class ErrorHandler:
"""Handles error collection and formatting"""
def __init__(self):
self.error_stack = []
def collect(self, error):
"""
Add an error to the stack
Args:
error: Error object (from lexer, parser, or validator)
"""
self.error_stack.append(error)
def get_errors(self):
"""Return all collected errors"""
return self.error_stack
def clear(self):
"""Clear all errors"""
self.error_stack = []
def format_error(self, error):
"""
Format a single error for display
Args:
error: Error object
Returns:
Formatted error string
"""
if hasattr(error, 'id'):
# Validation error
return (
f"Error ID: {error.id}\n"
f"Type: {error.type}\n"
f"Message: {error.message}\n"
f"Line: {error.line}, Column: {error.column}\n"
)
else:
# Standard Python exception
return f"Error: {str(error)}\n"
def format_all_errors(self):
"""
Format all errors for display
Returns:
String with all formatted errors
"""
if not self.error_stack:
return "No errors"
output = []
output.append("=" * 60)
output.append("ERRORS DETECTED")
output.append("=" * 60)
for i, error in enumerate(self.error_stack, 1):
output.append(f"\n--- Error {i} ---")
output.append(self.format_error(error))
return "\n".join(output)