Database of error patterns and their fixes. Automatically learns from: - Errors encountered during execution - Fixes that resolved the error - User-provided solutions Provides: - Similar error lookup - Fix suggestions - Error frequency analysis
| 96 | |
| 97 | |
| 98 | class ErrorDatabase: |
| 99 | """ |
| 100 | Database of error patterns and their fixes. |
| 101 | |
| 102 | Automatically learns from: |
| 103 | - Errors encountered during execution |
| 104 | - Fixes that resolved the error |
| 105 | - User-provided solutions |
| 106 | |
| 107 | Provides: |
| 108 | - Similar error lookup |
| 109 | - Fix suggestions |
| 110 | - Error frequency analysis |
| 111 | """ |
| 112 | |
| 113 | # Error type categorization |
| 114 | ERROR_CATEGORIES = { |
| 115 | "ModuleNotFoundError": "import", |
| 116 | "ImportError": "import", |
| 117 | "SyntaxError": "syntax", |
| 118 | "IndentationError": "syntax", |
| 119 | "NameError": "name_reference", |
| 120 | "TypeError": "type", |
| 121 | "ValueError": "value", |
| 122 | "AttributeError": "attribute", |
| 123 | "KeyError": "key_access", |
| 124 | "IndexError": "index_access", |
| 125 | "FileNotFoundError": "file_io", |
| 126 | "PermissionError": "file_io", |
| 127 | "TimeoutError": "timeout", |
| 128 | "ConnectionError": "network", |
| 129 | "HTTPError": "network", |
| 130 | "AssertionError": "test_failure", |
| 131 | "pytest": "test_failure", |
| 132 | "unittest": "test_failure", |
| 133 | } |
| 134 | |
| 135 | # Common fix patterns |
| 136 | FIX_PATTERNS = { |
| 137 | "import": [ |
| 138 | ("ModuleNotFoundError", "pip install {module}"), |
| 139 | ("ImportError", "Check import path or install package"), |
| 140 | ], |
| 141 | "syntax": [ |
| 142 | ("SyntaxError", "Check line {line} for syntax issues"), |
| 143 | ("IndentationError", "Fix indentation at line {line}"), |
| 144 | ], |
| 145 | "file_io": [ |
| 146 | ("FileNotFoundError", "Create file or check path"), |
| 147 | ("PermissionError", "chmod +x or check permissions"), |
| 148 | ], |
| 149 | } |
| 150 | |
| 151 | def __init__(self): |
| 152 | self.state = get_state_store() |
| 153 | self._cache: Dict[str, ErrorPattern] = {} |
| 154 | self._load_database() |
| 155 |
no outgoing calls