debugging
Debugging
Scientific Method
- Observe - Gather information about the problem
- Hypothesize - Form a theory about the cause
- Predict - What would confirm/refute the hypothesis?
- Test - Run experiment to verify
- Iterate - Refine hypothesis based on results
Debugging Workflow
Step 1: Reproduce
Reproduction checklist:
- [ ] Can reproduce consistently
- [ ] Identified minimal steps to trigger
- [ ] Documented exact error message
- [ ] Noted environment (OS, versions, config)
Step 2: Isolate
Narrow down the problem:
- Binary search through code changes
- Comment out sections to find culprit
- Test with minimal input/config
- Check if issue exists in isolation
Step 3: Investigate
# Check recent changes
git log --oneline -20
git diff HEAD~5
# Search for related code
grep -r "errorPattern" src/
# Check logs and stack traces
Step 4: Fix
- Understand the root cause (not just symptoms)
- Write a failing test that reproduces the bug
- Implement the fix
- Verify the test passes
- Check for similar issues elsewhere
Step 5: Verify
Verification checklist:
- [ ] Original issue is fixed
- [ ] Test added to prevent regression
- [ ] No new issues introduced
- [ ] Related code reviewed for similar bugs
Common Patterns
| Symptom | Check First |
|---|---|
| "Works on my machine" | Environment differences, versions |
| Intermittent failures | Race conditions, timing, caching |
| Null/undefined errors | Data flow, initialization order |
| Performance degradation | N+1 queries, memory leaks, loops |
| Silent failures | Error handling, logging gaps |
Anti-Patterns
- Shotgun debugging: Random changes hoping something works
- Print debugging only: Use proper debugger and logging
- Fixing symptoms: Address root cause, not surface issues
- Untested fixes: Always verify with tests
More from mrwogu/promptscript
refactoring
Improves code structure without changing behavior. Use when cleaning up code, reducing complexity, or when asked to refactor.
1pull-requesting
Creates well-structured pull requests with clear descriptions. Use when creating PRs, preparing changes for review, or when asked to open a pull request.
1code-reviewing
Reviews code for bugs, security issues, and quality improvements. Use when reviewing pull requests, checking code quality, or when asked to review changes.
1documenting
Creates clear, maintainable documentation for code and APIs. Use when writing README files, API docs, code comments, or when asked to document code.
1testing-code
Writes comprehensive tests following AAA pattern. Use for unit and integration tests.
1security-auditing
Audits code for security vulnerabilities and OWASP issues. Use when reviewing security, checking for vulnerabilities, or when asked to audit code security.
1