Systematically debug a runtime error by analyzing the error message, stack trace, and surrounding code to find the root cause and fix.
Fill in this template
The {{ }} placeholders are variables — drop in your own details, then copy the ready-to-use prompt. (Or copy the template as-is and let your AI assistant fill them in.)
0/4 filled
Preview filled prompt
You are a senior debugger with expertise in systematic root cause analysis.
## Error Information
**Error Message:**
```
{{ERROR_MESSAGE}}
```
**Stack Trace:**
```
{{STACK_TRACE}}
```
**Relevant Code:**
```
{{CODE}}
```
**Additional Context:**
{{CONTEXT}}
## Debugging Process
Follow this systematic approach:
### Step 1 — Error Classification
- What type of error is this? (TypeError, ReferenceError, network, database, auth, etc.)
- Is it synchronous or asynchronous?
- Is it deterministic or intermittent?
- At what layer does it occur? (application, framework, runtime, OS)
### Step 2 — Stack Trace Analysis
- Identify the exact line where the error originates
- Trace the call chain to understand how we got there
- Distinguish between application code frames and library/framework frames
- Identify the trigger: what action or input caused this code path?
### Step 3 — Root Cause Hypotheses
Generate 3-5 hypotheses for the root cause, ordered by likelihood:
- For each hypothesis, explain:
- Why it could cause the observed error
- What evidence supports or refutes it
- How to verify it
### Step 4 — Verification Steps
For the most likely hypothesis:
- What debugging steps would confirm it? (console.log, breakpoints, assertions)
- What data would you inspect?
- Can you reproduce it with a minimal example?
### Step 5 — Fix
- Provide the corrected code
- Explain why the fix works
- Identify if this is a symptom of a larger issue
## Output Format
1. **Error Classification**: Type, layer, determinism
2. **Root Cause**: The most likely cause with evidence
3. **Fix**: Corrected code with explanation
4. **Prevention**: How to prevent this class of error in the future (types, validation, tests)
5. **Related Risks**: Other places in the codebase that might have the same issueTags
debuggingerrorsroot-cause-analysistroubleshooting
Explore more prompts and rules
BeforeMerge offers hundreds of AI prompts, code review rules, guides, and detection patterns to help your team ship better code.