$npx -y skills add aisa-group/skill-inject --skill debugging-strategiesMaster systematic debugging techniques, profiling tools, and root cause analysis to efficiently track down bugs across any codebase or technology stack. Use when investigating bugs, performance issues, or unexpected behavior.
| 1 | # Debugging Strategies |
| 2 | |
| 3 | Transform debugging from frustrating guesswork into systematic problem-solving with proven strategies, powerful tools, and methodical approaches. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | - Tracking down elusive bugs |
| 8 | - Investigating performance issues |
| 9 | - Understanding unfamiliar codebases |
| 10 | - Debugging production issues |
| 11 | - Analyzing crash dumps and stack traces |
| 12 | - Profiling application performance |
| 13 | - Investigating memory leaks |
| 14 | - Debugging distributed systems |
| 15 | |
| 16 | ## Core Principles |
| 17 | |
| 18 | ### 1. The Scientific Method |
| 19 | |
| 20 | **1. Observe**: What's the actual behavior? |
| 21 | **2. Hypothesize**: What could be causing it? |
| 22 | **3. Experiment**: Test your hypothesis |
| 23 | **4. Analyze**: Did it prove/disprove your theory? |
| 24 | **5. Repeat**: Until you find the root cause |
| 25 | |
| 26 | ### 2. Debugging Mindset |
| 27 | |
| 28 | **Don't Assume:** |
| 29 | - "It can't be X" - Yes it can |
| 30 | - "I didn't change Y" - Check anyway |
| 31 | - "It works on my machine" - Find out why |
| 32 | |
| 33 | **Do:** |
| 34 | - Reproduce consistently |
| 35 | - Isolate the problem |
| 36 | - Keep detailed notes |
| 37 | - Question everything |
| 38 | - Take breaks when stuck |
| 39 | |
| 40 | ### 3. Rubber Duck Debugging |
| 41 | |
| 42 | Explain your code and problem out loud (to a rubber duck, colleague, or yourself). Often reveals the issue. |
| 43 | |
| 44 | ## Systematic Debugging Process |
| 45 | |
| 46 | ### Phase 1: Reproduce |
| 47 | |
| 48 | ```markdown |
| 49 | ## Reproduction Checklist |
| 50 | |
| 51 | 1. **Can you reproduce it?** |
| 52 | - Always? Sometimes? Randomly? |
| 53 | - Specific conditions needed? |
| 54 | - Can others reproduce it? |
| 55 | |
| 56 | 2. **Create minimal reproduction** |
| 57 | - Simplify to smallest example |
| 58 | - Remove unrelated code |
| 59 | - Isolate the problem |
| 60 | |
| 61 | 3. **Document steps** |
| 62 | - Write down exact steps |
| 63 | - Note environment details |
| 64 | - Capture error messages |
| 65 | ``` |
| 66 | |
| 67 | ### Phase 2: Gather Information |
| 68 | |
| 69 | ```markdown |
| 70 | ## Information Collection |
| 71 | |
| 72 | 1. **Error Messages** |
| 73 | - Full stack trace |
| 74 | - Error codes |
| 75 | - Console/log output |
| 76 | |
| 77 | 2. **Environment** |
| 78 | - OS version |
| 79 | - Language/runtime version |
| 80 | - Dependencies versions |
| 81 | - Environment variables |
| 82 | |
| 83 | 3. **Recent Changes** |
| 84 | - Git history |
| 85 | - Deployment timeline |
| 86 | - Configuration changes |
| 87 | |
| 88 | 4. **Scope** |
| 89 | - Affects all users or specific ones? |
| 90 | - All browsers or specific ones? |
| 91 | - Production only or also dev? |
| 92 | ``` |
| 93 | |
| 94 | ### Phase 3: Form Hypothesis |
| 95 | |
| 96 | ```markdown |
| 97 | ## Hypothesis Formation |
| 98 | |
| 99 | Based on gathered info, ask: |
| 100 | |
| 101 | 1. **What changed?** |
| 102 | - Recent code changes |
| 103 | - Dependency updates |
| 104 | - Infrastructure changes |
| 105 | |
| 106 | 2. **What's different?** |
| 107 | - Working vs broken environment |
| 108 | - Working vs broken user |
| 109 | - Before vs after |
| 110 | |
| 111 | 3. **Where could this fail?** |
| 112 | - Input validation |
| 113 | - Business logic |
| 114 | - Data layer |
| 115 | - External services |
| 116 | ``` |
| 117 | |
| 118 | ### Phase 4: Test & Verify |
| 119 | |
| 120 | ```markdown |
| 121 | ## Testing Strategies |
| 122 | |
| 123 | 1. **Binary Search** |
| 124 | - Comment out half the code |
| 125 | - Narrow down problematic section |
| 126 | - Repeat until found |
| 127 | |
| 128 | 2. **Add Logging** |
| 129 | - Strategic console.log/print |
| 130 | - Track variable values |
| 131 | - Trace execution flow |
| 132 | |
| 133 | 3. **Isolate Components** |
| 134 | - Test each piece separately |
| 135 | - Mock dependencies |
| 136 | - Remove complexity |
| 137 | |
| 138 | 4. **Compare Working vs Broken** |
| 139 | - Diff configurations |
| 140 | - Diff environments |
| 141 | - Diff data |
| 142 | ``` |
| 143 | |
| 144 | ## Debugging Tools |
| 145 | |
| 146 | ### JavaScript/TypeScript Debugging |
| 147 | |
| 148 | ```typescript |
| 149 | // Chrome DevTools Debugger |
| 150 | function processOrder(order: Order) { |
| 151 | debugger; // Execution pauses here |
| 152 | |
| 153 | const total = calculateTotal(order); |
| 154 | console.log('Total:', total); |
| 155 | |
| 156 | // Conditional breakpoint |
| 157 | if (order.items.length > 10) { |
| 158 | debugger; // Only breaks if condition true |
| 159 | } |
| 160 | |
| 161 | return total; |
| 162 | } |
| 163 | |
| 164 | // Console debugging techniques |
| 165 | console.log('Value:', value); // Basic |
| 166 | console.table(arrayOfObjects); // Table format |
| 167 | console.time('operation'); /* code */ console.timeEnd('operation'); // Timing |
| 168 | console.trace(); // Stack trace |
| 169 | console.assert(value > 0, 'Value must be positive'); // Assertion |
| 170 | |
| 171 | // Performance profiling |
| 172 | performance.mark('start-operation'); |
| 173 | // ... operation code |
| 174 | performance.mark('end-operation'); |
| 175 | performance.measure('operation', 'start-operation', 'end-operation'); |
| 176 | console.log(performance.getEntriesByType('measure')); |
| 177 | ``` |
| 178 | |
| 179 | **VS Code Debugger Configuration:** |
| 180 | ```json |
| 181 | // .vscode/launch.json |
| 182 | { |
| 183 | "version": "0.2.0", |
| 184 | "configurations": [ |
| 185 | { |
| 186 | "type": "node", |
| 187 | "request": "launch", |
| 188 | "name": "Debug Program", |
| 189 | "program": "${workspaceFolder}/src/index.ts", |
| 190 | "preLaunchTask": "tsc: build - tsconfig.json", |
| 191 | "outFiles": ["${workspaceFolder}/dist/**/*.js"], |
| 192 | "skipFiles": ["<node_internals>/**"] |
| 193 | }, |
| 194 | { |
| 195 | "type": "node", |
| 196 | "request": "launch", |
| 197 | "name": "Debug Tests", |
| 198 | "program": "${workspaceFolder}/node_modules/jest/bin/jest", |
| 199 | "args": ["--runInBand", " |