Back to prompts
CodingChatGPTClaudeGemini

Debugging Detective

Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.

Prompt Template

You are a senior debugging specialist. Help me find and fix this bug systematically.

**What should happen:** [expected behavior]
**What actually happens:** [actual behavior]
**Error message (if any):**
```
[paste error/stack trace]
```
**Environment:** [OS, language version, framework version, relevant packages]
**When it started:** [always / after a specific change / intermittent]
**What I've already tried:** [list attempts]

**Relevant code:**
```
[paste code]
```

**Relevant config/dependencies:**
```
[paste if relevant]
```

Please:
1. **Parse the error** — explain what the error message actually means in plain English
2. **Identify likely root causes** — rank from most to least probable
3. **Diagnostic steps** — what I should check/log to confirm the root cause
4. **Fix** — provide the specific code change for the most likely cause
5. **Prevention** — how to prevent this class of bug in the future (linting rules, types, tests)
6. **If my code isn't the issue** — check for known framework bugs, dependency conflicts, or environment issues

Example Output

Error Analysis

What the error means:

`TypeError: Cannot read properties of undefined (reading 'map')` on line 42 means `data.items` is `undefined` when your component tries to render. The API response doesn't have the shape your code expects.

Most Likely Causes (ranked)

1. **Race condition** (90% likely) — Component renders before the API call completes. `data` is `undefined` during the initial render.

2. **API response shape changed** (5%) — The API might return `{results: [...]}` instead of `{items: [...]}`

3. **Error response not handled** (5%) — API returns an error object that doesn't have `.items`

Fix

// Add optional chaining and a loading state

const items = data?.items ?? [];

if (isLoading) return <Skeleton />;

return items.map(item => <Card key={item.id} {...item} />);

Prevention

- Add TypeScript types for your API responses

- Use Zod to validate API responses at runtime

- Add a `<Suspense>` boundary or loading state for async data

Tips for Best Results

  • 💡Include the FULL stack trace — the root cause is often several frames deep
  • 💡Mention what changed recently — new packages, version upgrades, config changes
  • 💡For intermittent bugs, describe the frequency and any patterns you've noticed
  • 💡Include browser console output for frontend bugs