|
| 1 | +--- |
| 2 | +name: Error Resolver |
| 3 | +description: Systematic error diagnosis and resolution using first-principle analysis. Use when encountering any error message, stack trace, or unexpected behavior. Supports replay functionality to record and reuse solutions. |
| 4 | +--- |
| 5 | + |
| 6 | +# Error Resolver |
| 7 | + |
| 8 | +A first-principle approach to diagnosing and resolving errors across all languages and frameworks. |
| 9 | + |
| 10 | +## Core Philosophy |
| 11 | + |
| 12 | +**The 5-step Error Resolution Process:** |
| 13 | + |
| 14 | +``` |
| 15 | +1. CLASSIFY -> 2. PARSE -> 3. MATCH -> 4. ANALYZE -> 5. RESOLVE |
| 16 | + | | | | | |
| 17 | + What type? Extract key Known Root cause Fix + |
| 18 | + information pattern? analysis Prevent |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +When you encounter an error: |
| 24 | + |
| 25 | +1. **Paste the full error** (including stack trace if available) |
| 26 | +2. **Provide context** (what were you trying to do?) |
| 27 | +3. **Share relevant code** (the file/function involved) |
| 28 | + |
| 29 | +## Error Classification Framework |
| 30 | + |
| 31 | +### Primary Categories |
| 32 | + |
| 33 | +| Category | Indicators | Common Causes | |
| 34 | +|----------|------------|---------------| |
| 35 | +| **Syntax** | Parse error, Unexpected token | Typos, missing brackets, invalid syntax | |
| 36 | +| **Type** | TypeError, type mismatch | Wrong data type, null/undefined access | |
| 37 | +| **Reference** | ReferenceError, NameError | Undefined variable, scope issues | |
| 38 | +| **Runtime** | RuntimeError, Exception | Logic errors, invalid operations | |
| 39 | +| **Network** | ECONNREFUSED, timeout, 4xx/5xx | Connection issues, wrong URL, server down | |
| 40 | +| **Permission** | EACCES, PermissionError | File/directory access, sudo needed | |
| 41 | +| **Dependency** | ModuleNotFound, Cannot find module | Missing package, version mismatch | |
| 42 | +| **Configuration** | Config error, env missing | Wrong settings, missing env vars | |
| 43 | +| **Database** | Connection refused, query error | DB down, wrong credentials, bad query | |
| 44 | +| **Memory** | OOM, heap out of memory | Memory leak, large data processing | |
| 45 | + |
| 46 | +### Secondary Attributes |
| 47 | + |
| 48 | +- **Severity**: Fatal / Error / Warning / Info |
| 49 | +- **Scope**: Build-time / Runtime / Test-time |
| 50 | +- **Origin**: User code / Framework / Third-party / System |
| 51 | + |
| 52 | +## Analysis Workflow |
| 53 | + |
| 54 | +### Step 1: Classify |
| 55 | + |
| 56 | +Identify the error category by examining: |
| 57 | +- Error name/code (e.g., `ENOENT`, `TypeError`) |
| 58 | +- Error message keywords |
| 59 | +- Where it occurred (compile, runtime, test) |
| 60 | + |
| 61 | +### Step 2: Parse |
| 62 | + |
| 63 | +Extract key information: |
| 64 | +``` |
| 65 | +- Error code: [specific code if any] |
| 66 | +- File path: [where the error originated] |
| 67 | +- Line number: [exact line if available] |
| 68 | +- Function/method: [context of the error] |
| 69 | +- Variable/value: [what was involved] |
| 70 | +- Stack trace depth: [how deep is the call stack] |
| 71 | +``` |
| 72 | + |
| 73 | +### Step 3: Match Patterns |
| 74 | + |
| 75 | +Check against known error patterns: |
| 76 | +- See `patterns/` directory for language-specific patterns |
| 77 | +- Match error signatures to known solutions |
| 78 | +- Check replay history for previous solutions |
| 79 | + |
| 80 | +### Step 4: Root Cause Analysis |
| 81 | + |
| 82 | +Apply the **5 Whys** technique: |
| 83 | +``` |
| 84 | +Error: Cannot read property 'name' of undefined |
| 85 | + Why 1? -> user object is undefined |
| 86 | + Why 2? -> API call returned null |
| 87 | + Why 3? -> User ID doesn't exist in database |
| 88 | + Why 4? -> ID was from stale cache |
| 89 | + Why 5? -> Cache invalidation not implemented |
| 90 | +
|
| 91 | +Root Cause: Missing cache invalidation logic |
| 92 | +``` |
| 93 | + |
| 94 | +### Step 5: Resolve |
| 95 | + |
| 96 | +Generate actionable solution: |
| 97 | +1. **Immediate fix** - Get it working now |
| 98 | +2. **Proper fix** - The right way to solve it |
| 99 | +3. **Prevention** - How to avoid in the future |
| 100 | + |
| 101 | +## Output Format |
| 102 | + |
| 103 | +When resolving an error, provide: |
| 104 | + |
| 105 | +``` |
| 106 | +## Error Diagnosis |
| 107 | +
|
| 108 | +**Classification**: [Category] / [Severity] / [Scope] |
| 109 | +
|
| 110 | +**Error Signature**: |
| 111 | +- Code: [error code] |
| 112 | +- Type: [error type] |
| 113 | +- Location: [file:line] |
| 114 | +
|
| 115 | +## Root Cause |
| 116 | +
|
| 117 | +[Explanation of why this error occurred] |
| 118 | +
|
| 119 | +**Contributing Factors**: |
| 120 | +1. [Factor 1] |
| 121 | +2. [Factor 2] |
| 122 | +
|
| 123 | +## Solution |
| 124 | +
|
| 125 | +### Immediate Fix |
| 126 | +[Quick steps to resolve] |
| 127 | +
|
| 128 | +### Code Change |
| 129 | +[Specific code to add/modify] |
| 130 | +
|
| 131 | +### Verification |
| 132 | +[How to verify the fix works] |
| 133 | +
|
| 134 | +## Prevention |
| 135 | +
|
| 136 | +[How to prevent this error in the future] |
| 137 | +
|
| 138 | +## Replay Tag |
| 139 | +
|
| 140 | +[Unique identifier for this solution - for future reference] |
| 141 | +``` |
| 142 | + |
| 143 | +## Replay System |
| 144 | + |
| 145 | +The replay system records successful solutions for future reference. |
| 146 | + |
| 147 | +### Recording a Solution |
| 148 | + |
| 149 | +After resolving an error, record it: |
| 150 | + |
| 151 | +```bash |
| 152 | +# Create solution record in project |
| 153 | +mkdir -p .claude/error-solutions |
| 154 | + |
| 155 | +# Solution file format: [error-type]-[hash].yaml |
| 156 | +``` |
| 157 | + |
| 158 | +### Solution Record Format |
| 159 | + |
| 160 | +```yaml |
| 161 | +# .claude/error-solutions/[error-signature].yaml |
| 162 | +id: "nodejs-module-not-found-express" |
| 163 | +created: "2024-01-15T10:30:00Z" |
| 164 | +updated: "2024-01-20T14:22:00Z" |
| 165 | + |
| 166 | +error: |
| 167 | + type: "dependency" |
| 168 | + category: "ModuleNotFound" |
| 169 | + language: "nodejs" |
| 170 | + pattern: "Cannot find module 'express'" |
| 171 | + context: "npm project, missing dependency" |
| 172 | + |
| 173 | +diagnosis: |
| 174 | + root_cause: "Package not installed or node_modules corrupted" |
| 175 | + factors: |
| 176 | + - "Missing npm install after git clone" |
| 177 | + - "Corrupted node_modules directory" |
| 178 | + - "Package not in package.json" |
| 179 | + |
| 180 | +solution: |
| 181 | + immediate: |
| 182 | + - "Run: npm install express" |
| 183 | + proper: |
| 184 | + - "Check package.json has express listed" |
| 185 | + - "Run: rm -rf node_modules && npm install" |
| 186 | + code_change: null |
| 187 | + |
| 188 | +verification: |
| 189 | + - "Run the application again" |
| 190 | + - "Check express is in node_modules" |
| 191 | + |
| 192 | +prevention: |
| 193 | + - "Add npm install to project setup docs" |
| 194 | + - "Use npm ci in CI/CD pipelines" |
| 195 | + |
| 196 | +metadata: |
| 197 | + occurrences: 5 |
| 198 | + last_resolved: "2024-01-20T14:22:00Z" |
| 199 | + success_rate: 1.0 |
| 200 | + tags: ["nodejs", "npm", "dependency"] |
| 201 | +``` |
| 202 | +
|
| 203 | +### Replay Lookup |
| 204 | +
|
| 205 | +When encountering an error: |
| 206 | +1. Generate error signature from the error message |
| 207 | +2. Search `.claude/error-solutions/` for matching patterns |
| 208 | +3. If found, apply the recorded solution |
| 209 | +4. If new, proceed with full analysis and record the solution |
| 210 | + |
| 211 | +### Error Signature Generation |
| 212 | + |
| 213 | +``` |
| 214 | +signature = hash( |
| 215 | + error_type + |
| 216 | + error_code + |
| 217 | + normalized_message + # remove specific values |
| 218 | + language + |
| 219 | + framework |
| 220 | +) |
| 221 | +``` |
| 222 | +
|
| 223 | +Example transformations: |
| 224 | +- `Cannot find module 'express'` -> `Cannot find module '{module}'` |
| 225 | +- `TypeError: Cannot read property 'name' of undefined` -> `TypeError: Cannot read property '{prop}' of undefined` |
| 226 | +
|
| 227 | +## Debug Commands |
| 228 | +
|
| 229 | +Useful commands during debugging: |
| 230 | +
|
| 231 | +### Node.js |
| 232 | +```bash |
| 233 | +# Verbose error output |
| 234 | +NODE_DEBUG=* node app.js |
| 235 | +
|
| 236 | +# Memory debugging |
| 237 | +node --inspect app.js |
| 238 | +
|
| 239 | +# Check installed packages |
| 240 | +npm ls [package-name] |
| 241 | +
|
| 242 | +# Verify package.json |
| 243 | +npm ls --depth=0 |
| 244 | +``` |
| 245 | + |
| 246 | +### Python |
| 247 | +```bash |
| 248 | +# Debug mode |
| 249 | +python -m pdb script.py |
| 250 | + |
| 251 | +# Check installed packages |
| 252 | +pip show [package-name] |
| 253 | +pip list |
| 254 | +``` |
| 255 | + |
| 256 | +### General |
| 257 | +```bash |
| 258 | +# Check file permissions |
| 259 | +ls -la [file] |
| 260 | + |
| 261 | +# Check port usage |
| 262 | +lsof -i :[port] |
| 263 | +netstat -an | grep [port] |
| 264 | + |
| 265 | +# Check environment variables |
| 266 | +env | grep [VAR_NAME] |
| 267 | +printenv [VAR_NAME] |
| 268 | + |
| 269 | +# Check disk space |
| 270 | +df -h |
| 271 | + |
| 272 | +# Check memory |
| 273 | +free -m # Linux |
| 274 | +vm_stat # macOS |
| 275 | +``` |
| 276 | + |
| 277 | +## Common Debugging Patterns |
| 278 | + |
| 279 | +### Pattern 1: Binary Search |
| 280 | +When the error location is unclear: |
| 281 | +1. Comment out half the code |
| 282 | +2. If error persists, it's in the remaining half |
| 283 | +3. Repeat until you find the exact line |
| 284 | + |
| 285 | +### Pattern 2: Minimal Reproduction |
| 286 | +Create the smallest code that reproduces the error: |
| 287 | +1. Start with empty file |
| 288 | +2. Add code piece by piece |
| 289 | +3. Stop when error appears |
| 290 | +4. That's your minimal repro case |
| 291 | + |
| 292 | +### Pattern 3: Rubber Duck Debugging |
| 293 | +Explain the problem out loud (or to Claude): |
| 294 | +1. What should happen? |
| 295 | +2. What actually happens? |
| 296 | +3. What changed recently? |
| 297 | +4. What assumptions am I making? |
| 298 | + |
| 299 | +### Pattern 4: Git Bisect |
| 300 | +Find which commit introduced the bug: |
| 301 | +```bash |
| 302 | +git bisect start |
| 303 | +git bisect bad # current commit is bad |
| 304 | +git bisect good [last-known-good-commit] |
| 305 | +# Git will checkout commits for you to test |
| 306 | +git bisect good/bad # mark each as good or bad |
| 307 | +git bisect reset # when done |
| 308 | +``` |
| 309 | + |
| 310 | +## Reference Files |
| 311 | + |
| 312 | +- **patterns/** - Language-specific error patterns |
| 313 | + - `nodejs.md` - Node.js common errors |
| 314 | + - `python.md` - Python common errors |
| 315 | + - `react.md` - React/Next.js errors |
| 316 | + - `database.md` - Database errors |
| 317 | + - `docker.md` - Docker/container errors |
| 318 | + - `git.md` - Git errors |
| 319 | + - `network.md` - Network/API errors |
| 320 | + |
| 321 | +- **analysis/** - Analysis methodologies |
| 322 | + - `stack-trace.md` - Stack trace parsing guide |
| 323 | + - `root-cause.md` - Root cause analysis techniques |
| 324 | + |
| 325 | +- **replay/** - Replay system |
| 326 | + - `solution-template.yaml` - Template for recording solutions |
0 commit comments