Debug an error step by step
Find the root cause of a programming error with a structured diagnostic method instead of blind patches. Designed for ChatGPT, Claude, Gemini and Microsoft Copilot. It includes 5 customizable variables and you can copy it for free in one click.
Beginner · Code · Pending editorial review
Prompt
Act as a senior software engineer who is an expert at debugging. I have an error in a {{language}} project.
Error message / behavior:
```
{{error}}
```
Relevant code:
```
{{code}}
```
What I expected to happen: {{expected}}
What I have already tried: {{tried}}
Follow this process and do not skip steps:
1. Explain in plain language what the error means.
2. List the 3 most likely causes ordered by probability, backing each one with evidence from the code.
3. For the most likely cause, explain how to confirm it (what to log, what to check).
4. Propose the minimal fix and show only the changed lines.
5. Explain why the fix works and whether it could affect other parts.
6. Suggest a test that would have caught this error.
If you lack information to be confident, ask me before proposing a solution.How to use it
Include the full error message (with stack trace) and only the related code. Remove API keys, passwords and personal data before pasting.
Usage example
Language: JavaScript · Error: TypeError: Cannot read properties of undefined (reading 'map') when loading a list from an API.
Sample output
1. What the error means
You are calling .map() on something that is undefined. In React this usually happens on the first render, before the API data arrives.
2. Most likely causes
- State starts with no value (
useState<Product[]>()) and renders before thefetchresolves. - The API returns a different shape, e.g.
{ data: [...] }, and you store the whole object. - A silent network error: the
catchleaves the state asundefined.
3. How to confirm it
Add console.log('products', products) right before the return and inspect the response in the Network tab.
4. Minimal fix
const [products, setProducts] = useState<Product[]>([]);
useEffect(() => {
fetch(API_URL)
.then((res) => res.json())
.then((json: { data?: Product[] }) => setProducts(json.data ?? []));
}, []);
Initializing with [] makes the first render show an empty list instead of crashing, and ?? [] guards against responses without data. It won't affect other parts unless something relies on products being undefined.
Since I haven't seen your code yet, please confirm the exact shape of the API response…
Key facts
- Category
- Programming & development · Debugging
- Output type
- Code
- Level
- Beginner
- Designed for
- ChatGPT, Claude, Gemini and Microsoft Copilot
- Verified in
- Pending editorial verification
- Variables
- Language / framework, Error message, Relevant code, Expected behavior and What you tried
- Language
- English
- Price
- Free, no sign-up
- Updated
- Nov 7, 2026
Frequently asked questions
How much code should I paste?
The function where the error happens, the code that calls it and the full error message or stack trace. Remove passwords, API keys and personal data first.
Why does the AI ask me questions instead of giving a fix?
That is intentional: a fix based on guesses can hide the real cause. Answer its questions or run the checks it suggests and paste the results.
What is this prompt for?
Find the root cause of a programming error with a structured diagnostic method instead of blind patches.
Which AI tools does it work with?
It is designed for ChatGPT, Claude, Gemini and Microsoft Copilot. We have not verified it in these tools yet, so results may vary between them.
How do I customize the prompt?
Click “Customize” and fill in the variables (Language / framework, Error message, Relevant code, Expected behavior and What you tried). The text updates instantly and you can then copy it in one click. Values are stored only in your browser.
Do I need experience to use it?
No. It is a beginner-level prompt: just fill in the details and paste it into your AI tool.
Is this prompt free?
Yes. Every HomeCasa Prompts prompt is free, with no sign-up or subscription. You can also use them in professional projects.
Can I trust the AI output?
Treat it as a high-quality draft: always check data, figures and important claims before publishing or making decisions.