Loading...
Loading...
Guides systematic root-cause debugging. Use when tests fail, builds break, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need a systematic approach to finding and fixing the root cause rather than guessing.
npx skill4agent add addyosmani/agent-skills debugging-and-error-recovery1. STOP adding features or making changes
2. PRESERVE evidence (error output, logs, repro steps)
3. DIAGNOSE using the triage checklist
4. FIX the root cause
5. GUARD against recurrence
6. RESUME only after verification passesCan you reproduce the failure?
├── YES → Proceed to Step 2
└── NO
├── Gather more context (logs, environment details)
├── Try reproducing in a minimal environment
└── If truly non-reproducible, document conditions and monitorCannot reproduce on demand:
├── Timing-dependent?
│ ├── Add timestamps to logs around the suspected area
│ ├── Try with artificial delays (setTimeout, sleep) to widen race windows
│ └── Run under load or concurrency to increase collision probability
├── Environment-dependent?
│ ├── Compare Node/browser versions, OS, environment variables
│ ├── Check for differences in data (empty vs populated database)
│ └── Try reproducing in CI where the environment is clean
├── State-dependent?
│ ├── Check for leaked state between tests or requests
│ ├── Look for global variables, singletons, or shared caches
│ └── Run the failing scenario in isolation vs after other operations
└── Truly random?
├── Add defensive logging at the suspected location
├── Set up an alert for the specific error signature
└── Document the conditions observed and revisit when it recurs# Run the specific failing test
npm test -- --grep "test name"
# Run with verbose output
npm test -- --verbose
# Run in isolation (rules out test pollution)
npm test -- --testPathPattern="specific-file" --runInBandWhich layer is failing?
├── UI/Frontend → Check console, DOM, network tab
├── API/Backend → Check server logs, request/response
├── Database → Check queries, schema, data integrity
├── Build tooling → Check config, dependencies, environment
├── External service → Check connectivity, API changes, rate limits
└── Test itself → Check if the test is correct (false negative)# Find which commit introduced the bug
git bisect start
git bisect bad # Current commit is broken
git bisect good <known-good-sha> # This commit worked
# Git will checkout midpoint commits; run your test at each
git bisect run npm test -- --grep "failing test"Symptom: "The user list shows duplicate entries"
Symptom fix (bad):
→ Deduplicate in the UI component: [...new Set(users)]
Root cause fix (good):
→ The API endpoint has a JOIN that produces duplicates
→ Fix the query, add a DISTINCT, or fix the data model// The bug: task titles with special characters broke the search
it('finds tasks with special characters in title', async () => {
await createTask({ title: 'Fix "quotes" & <brackets>' });
const results = await searchTasks('quotes');
expect(results).toHaveLength(1);
expect(results[0].title).toBe('Fix "quotes" & <brackets>');
});# Run the specific test
npm test -- --grep "specific test"
# Run the full test suite (check for regressions)
npm test
# Build the project (check for type/compilation errors)
npm run build
# Manual spot check if applicable
npm run dev # Verify in browserTest fails after code change:
├── Did you change code the test covers?
│ └── YES → Check if the test or the code is wrong
│ ├── Test is outdated → Update the test
│ └── Code has a bug → Fix the code
├── Did you change unrelated code?
│ └── YES → Likely a side effect → Check shared state, imports, globals
└── Test was already flaky?
└── Check for timing issues, order dependence, external dependenciesBuild fails:
├── Type error → Read the error, check the types at the cited location
├── Import error → Check the module exists, exports match, paths are correct
├── Config error → Check build config files for syntax/schema issues
├── Dependency error → Check package.json, run npm install
└── Environment error → Check Node version, OS compatibilityRuntime error:
├── TypeError: Cannot read property 'x' of undefined
│ └── Something is null/undefined that shouldn't be
│ → Check data flow: where does this value come from?
├── Network error / CORS
│ └── Check URLs, headers, server CORS config
├── Render error / White screen
│ └── Check error boundary, console, component tree
└── Unexpected behavior (no error)
└── Add logging at key points, verify data at each step// Safe default + warning (instead of crashing)
function getConfig(key: string): string {
const value = process.env[key];
if (!value) {
console.warn(`Missing config: ${key}, using default`);
return DEFAULTS[key] ?? '';
}
return value;
}
// Graceful degradation (instead of broken feature)
function renderChart(data: ChartData[]) {
if (data.length === 0) {
return <EmptyState message="No data available for this period" />;
}
try {
return <Chart data={data} />;
} catch (error) {
console.error('Chart render failed:', error);
return <ErrorState message="Unable to display chart" />;
}
}| Rationalization | Reality |
|---|---|
| "I know what the bug is, I'll just fix it" | You might be right 70% of the time. The other 30% costs hours. Reproduce first. |
| "The failing test is probably wrong" | Verify that assumption. If the test is wrong, fix the test. Don't just skip it. |
| "It works on my machine" | Environments differ. Check CI, check config, check dependencies. |
| "I'll fix it in the next commit" | Fix it now. The next commit will introduce new bugs on top of this one. |
| "This is a flaky test, ignore it" | Flaky tests mask real bugs. Fix the flakiness or understand why it's intermittent. |