Skip to content

πŸ› Debugging & Troubleshooting ​

Systematic approaches to finding and fixing bugs.

Debugging process ​

  1. Reproduce β€” Can you reliably trigger the bug?
  2. Isolate β€” Narrow down where the bug lives
  3. Understand β€” Read the code, understand the flow
  4. Hypothesize β€” Form a theory about the cause
  5. Test β€” Validate your hypothesis with minimal changes
  6. Fix β€” Apply the smallest correct fix
  7. Verify β€” Confirm the fix and check for regressions
  8. 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 ​

CategoryTypical causeHow to find
Off-by-oneLoop bounds, array indexingEdge case tests
Null referenceMissing null check, async timingStack trace, null assertions
Race conditionConcurrent access, async orderingStress tests, logs with timestamps
State mutationShared mutable state, side effectsDebugger, immutability
Config errorWrong env var, missing secretCheck 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

Pergame Knowledge Base