Debug Helper
Analyze bugs systematically and suggest fixes with explanations.
Important: Follow the Learning Mode guidelines in
_templates/learning-mode.md
Arguments
- •
$ARGUMENTS- Error message, file path, or description of the bug
Instructions
When the user runs /debug <problem>:
Step 1: Gather information
Ask if not provided:
- •"Error message chính xác là gì?"
- •"Bug xảy ra ở file/endpoint nào?"
- •"Có reproduce được không? Steps?"
- •"Gần đây có thay đổi gì liên quan không?"
Step 2: Analyze the problem
For Runtime Errors:
- •Read the error message and stack trace
- •Identify the failing line/file
- •Trace back to find root cause
- •Check related files
For Logic Bugs:
- •Understand expected vs actual behavior
- •Trace the data flow
- •Identify where logic diverges
- •Check edge cases
For API Errors:
- •Check request/response format
- •Verify authentication/authorization
- •Check database queries
- •Verify external service calls
Step 3: Report analysis
code
## 🐛 Bug Analysis ### Problem Summary [1-2 sentence description] ### Root Cause **What:** [What's wrong] **Where:** [File:line or component] **Why:** [Why it happens] ### Evidence ```code // The problematic code
Suggested Fix
code
// The fixed code
Explanation
[Why this fix works - teaching moment]
Prevention
[How to avoid similar bugs in future]
code
### Step 4: Interactive debugging After analysis, ask: - "Bạn có muốn tôi apply fix này không?" - "Bạn có muốn tôi giải thích kỹ hơn phần nào không?" - "Bạn hiểu tại sao bug xảy ra chưa?" ## Common Bug Patterns ### NestJS - Missing `@Injectable()` decorator - Circular dependency - Wrong module imports - Async/await missing ### Prisma - Missing `await` on queries - Wrong relation in `include` - Type mismatch in data ### React - Missing dependency in useEffect - State update on unmounted component - Wrong key in lists ### TypeScript - Null/undefined not handled - Type assertion hiding real issue - Generic type mismatch ## Debugging Strategies 1. **Binary Search**: Comment out half the code, narrow down 2. **Console.log**: Strategic logging at key points 3. **Rubber Duck**: Explain the code line by line 4. **Read Error Carefully**: Error messages often point to solution 5. **Check Recent Changes**: `git diff` to see what changed ## Example Usage
/debug "Cannot read property 'id' of undefined" /debug backend/src/modules/auth/auth.service.ts /debug "API returns 401 but user is logged in"
code
## After Completion Remind user: - "Nhớ update TRACKPAD.md với debugging lesson học được!" - Suggest: "Có muốn tôi tạo test case để prevent regression không?" - Share relevant debugging resources