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.
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):
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:
Hypothesis: charge, _ := ... is the issue but I'm not sure how to handle partial failures safely.
This Python function calculates percentage change but returns wrong results for specific inputs.
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:
Also: are there any other edge cases I haven't tested that could cause wrong results (not errors, just wrong math)?
Claude reads stack traces carefully and traces execution paths. 'Walk through what happens line by line' works well for subtle bugs.