AI is a remarkably effective debugging partner — not because it knows your codebase, but because explaining a bug clearly often reveals it, and the model asks the right diagnostic questions.
The rule: give it everything. Error message, code, expected vs. actual, what you already tried. Half-context produces half-answers.
02 Weak vs. Strong
EX 01Production nil pointer panic
Production panic happening for 2 days. Only under load — can't reproduce locally.
Full stack trace:
```
panic: runtime error: invalid memory address or nil pointer dereference
goroutine 47 [running]:
main.(*OrderService).ProcessOrder(...)
/app/service/orders.go:89 +0x2a4
```
Code (orders.go:85-95):
```go
func (s *OrderService) ProcessOrder(ctx context.Context, orderID string) (*Receipt, error) {
order, err := s.repo.FindOrder(ctx, orderID)
if err != nil {
return nil, err
}
charge, _ := s.payments.ChargeCard(ctx, order.Total, order.CustomerID)
receipt := &Receipt{
OrderID: order.ID,
ChargeID: charge.ID,
}
return receipt, nil
}
```
Expected: charge card, return receipt
Actual: panics at line 89 during high load
Already tried:
- Added logs — order is non-nil when function is called
- CustomerID is validated at the handler level
- The payment processor returns rate limit errors under load
Hypothesis: charge, _ := ... is the issue but I'm not sure how to handle partial failures safely.
→ Why it works
Full stack trace with line numbers. Exact code. Expected vs actual. What was already investigated.
EX 02Logic bug with test cases
This Python function calculates percentage change but returns wrong results for specific inputs.
```python
def percent_change(old_val, new_val):
return ((new_val - old_val) / old_val) * 100
```
Test cases:
| old_val | new_val | Expected | Actual | Status |
|---------|---------|----------|--------|--------|
| 100 | 150 | +50.0 | +50.0 | ✓ |
| 200 | 100 | -50.0 | -50.0 | ✓ |
| 0 | 50 | undefined | ZeroDivisionError | ✗ |
| -100 | -50 | +50.0 | +50.0 | ✓ |
The only failing case is old_val=0. I need to:
1. Handle it gracefully (return None when old_val is 0)
2. Understand why it's not caught by the try/except I have elsewhere
Also: are there any other edge cases I haven't tested that could cause wrong results (not errors, just wrong math)?
→ Why it works
All test cases shown with expected vs actual and pass/fail status. Exact behavior required for the edge case.
03 Key Points
01Give the full error with stack trace — never paraphrase it
02State expected AND actual behavior — not just 'it doesn't work'
03List what you already tried — prevents retreading dead ends
04Paste the minimum code that reproduces it, not your entire codebase
05Ask for root cause explanation, not just the fix
04 Model-Specific Notes
Claude reads stack traces carefully and traces execution paths. 'Walk through what happens line by line' works well for subtle bugs.
05 For Your Role
For any error: copy-paste the full error message (never retype it), what you were trying to do, and what you already tried. Triples response quality.