| name | Systematic Debugging |
| description | Four-phase root cause analysis for reliable bug fixes |
| version | 1.0.0 |
| source | Adapted from obra/superpowers |
Systematic Debugging
The Fundamental Rule
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.
Quick patches create technical debt. Symptoms mask deeper issues. Every fix must address the actual root cause.
The Four Phases
Phase 1: Root Cause Investigation
Before touching code, gather evidence:
-
Read the error carefully
Error: Cannot read properties of undefined (reading 'map')
at ProductList (src/components/ProductList.tsx:15:24)
at renderWithHooks (node_modules/react-dom/...)
- What exactly failed?
- Where in the stack trace?
- What data was involved?
-
Reproduce consistently
1. Navigate to /products
2. Click "Filter by category"
3. Select "Electronics"
4. Error appears
-
Check recent changes
git log --oneline -10
git diff HEAD~3 -- src/components/ProductList.tsx
-
Add instrumentation at boundaries
console.log('products:', JSON.stringify(products, null, 2));
console.log('type:', typeof products);
console.log('isArray:', Array.isArray(products));
Phase 2: Pattern Analysis
Find working examples and compare:
const WorkingList = ({ items }) => {
if (!items || items.length === 0) return <Empty />;
return items.map(item => <Item key={item.id} {...item} />);
};
const BrokenList = ({ items }) => {
return items.map(item => <Item key={item.id} {...item} />);
};
Key questions:
- What does working code do that broken code doesn't?
- What assumptions does broken code make?
- Where do the data flows diverge?
Phase 3: Hypothesis and Testing
Apply the scientific method:
-
Form specific hypothesis
"The error occurs because products is undefined on initial render before the API response arrives."
-
Test with minimal change
if (!products) return <Loading />;
-
One variable at a time
- Don't bundle multiple fixes
- Change one thing, test, observe
- Document what you learned
Phase 4: Implementation
-
Write failing test FIRST
it('should handle undefined products gracefully', () => {
render(<ProductList products={undefined} />);
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
-
Implement root cause fix
const ProductList = ({ products }: Props) => {
if (!products) return <Loading />;
if (products.length === 0) return <Empty />;
return (
<ul>
{products.map(product => (
<ProductItem key={product.id} product={product} />
))}
</ul>
);
};
-
Verify without bundling
- Only the fix, nothing else
- Run full test suite
- Confirm original issue resolved
Red Flags - Stop and Reassess
| Warning Sign | Action |
|---|
| Proposing fix before understanding | Go back to Phase 1 |
| Multiple simultaneous changes | Isolate to one change |
| Third fix attempt failing | Question the architecture |
| "It works but I don't know why" | Keep investigating |
The Three-Fix Rule
If you've tried 3 fixes without success:
- STOP - More fixes won't help
- Step back - Is the architecture flawed?
- Document - What did each attempt reveal?
- Reconsider - Is this the right approach at all?
Debugging Toolkit
Console Methods
console.log()
console.table()
console.trace()
console.time()
console.group()
React DevTools
- Component props inspection
- State timeline
- Profiler for performance
Network Tab
- Request/response payloads
- Timing analysis
- Failed requests
Breakpoints
debugger;
FrankX-Specific Patterns
Next.js Server Components
API Route Debugging
export async function POST(request: Request) {
console.log('=== API DEBUG ===');
const body = await request.json();
console.log('Body:', JSON.stringify(body, null, 2));
console.log('Headers:', Object.fromEntries(request.headers));
}
Hydration Mismatches
When to Use This Skill
- Any bug that isn't immediately obvious
- Bugs that "shouldn't be possible"
- Issues that keep coming back
- Problems others have already attempted to fix
Related Skills
test-driven-development - Write test for bug first
webapp-testing - E2E debugging with Playwright
verification-before-completion - Ensure fix actually works