π Debugging & Troubleshooting β
Systematic approaches to finding and fixing bugs.
Debugging process β
- Reproduce β Can you reliably trigger the bug?
- Isolate β Narrow down where the bug lives
- Understand β Read the code, understand the flow
- Hypothesize β Form a theory about the cause
- Test β Validate your hypothesis with minimal changes
- Fix β Apply the smallest correct fix
- Verify β Confirm the fix and check for regressions
- Document β Add a test, update docs if needed
Isolation techniques β
- Binary search β Comment out half the code, see if bug persists
- Minimal reproduction β Strip everything until only the bug remains
- Git bisect β Find the commit that introduced the bug
- Logging β Add strategic log statements around the suspected area
- Breakpoints β Step through execution in a debugger
Common bug categories β
| Category | Typical cause | How to find |
|---|---|---|
| Off-by-one | Loop bounds, array indexing | Edge case tests |
| Null reference | Missing null check, async timing | Stack trace, null assertions |
| Race condition | Concurrent access, async ordering | Stress tests, logs with timestamps |
| State mutation | Shared mutable state, side effects | Debugger, immutability |
| Config error | Wrong env var, missing secret | Check deployment config |
Debugging tools β
- Browser DevTools β Network, console, breakpoints, performance
- Debugger β VS Code, Chrome DevTools, pdb, delve
- Logging β Structured logs with context (request ID, user ID)
- Profiler β CPU/memory profiling for performance bugs
- git bisect β Binary search through commit history
When you're stuck β
- Explain the bug out loud (rubber duck debugging)
- Take a break β fresh eyes find bugs faster
- Read the error message carefully, including the full stack trace
- Check if the bug exists on main branch
- Search for the error message in issues/Stack Overflow