Debug an Error Message Step-by-Step
Get a structured debugging plan: error explanation, ranked root causes, tests, and fixes.
This prompt converts a confusing error into a methodical debugging session: plain-English explanation, ranked root causes, a concrete check for each, then the fix. Reach for it when you're stuck on an error you don't recognize and want a diagnosis path rather than a blind guess. The ranked-causes-plus-tests structure stops the model from confidently proposing one wrong fix and instead has you verify before you change anything.
I'm hitting this error in my [LANGUAGE/FRAMEWORK] code. Walk me through debugging. (1) Explain what the error message means in plain English. (2) List the 3 most likely root causes ranked by probability. (3) For each cause, give me a specific test or check I can run to confirm it. (4) Once we know the cause, suggest the fix. ERROR: [PASTE ERROR] RELEVANT CODE: [PASTE CODE]
What you can expect back
What the error means
'Cannot read properties of undefined (reading map)' means you called .map on something that is undefined. At ProductList.tsx:14, `data.products` is undefined at the moment of render.
Most likely causes (ranked)
1. Render happens before the query resolves — on first render `data` is undefined, so `data.products` throws. (Most likely.)
2. The API returns a shape without a top-level `products` key (e.g. the array is the root, or nested differently).
3. fetchProducts throws/returns undefined, leaving the query with no data.
Checks
1. Add `console.log(data)` above the return. If it logs `undefined` first then the object, it's the loading race.
2. Inspect the network response body — confirm it actually has a `products` field.
3. Log inside fetchProducts to confirm it returns and what it returns.
Likely fix (cause 1)
Guard the loading/empty state:
`const { data, isLoading } = useQuery(...);`
`if (isLoading || !data) return <Spinner />;`
Then map over `data.products ?? []`.Illustrative example — your results will vary by tool and inputs.
Get sharper results
- 01Paste the complete stack trace, not just the top line — the call chain often points at the real origin several frames down from where the error surfaces.
- 02Mention what you already tried and what changed right before the error appeared; it lets the model rule out causes instead of repeating your steps.
- 03Include version numbers in the language/framework field, since the same error can have different causes across major versions of a library.
- 04If the error is intermittent, say so explicitly — it shifts the ranked causes toward race conditions, caching, and environment differences.
- 05After you run the suggested checks, paste the results back and ask it to re-rank; the second pass is usually where the real fix lands.
Adapt it for your case
Ask just for steps 1 and 2 (explanation and ranked causes) when you want a fast read before deciding whether to dig in.
Add logs and metrics alongside the error and ask it to factor in timing, deploys, and traffic when ranking causes.
Append 'For each cause, explain the underlying concept so I recognize this class of error next time.'
Common questions
What if none of the three causes is right?
Run the suggested checks, paste the results back, and ask it to re-rank with the new evidence. Narrowing by elimination usually surfaces the real cause within a round or two.
How much code should I paste?
Enough to cover the failing line plus anything that feeds it — the function, its inputs, and any relevant config. Too little and the model guesses; too much and the signal gets diluted.
Can it debug errors from compiled or minified output?
Partially. Minified stack traces are hard to read, so include your source maps or the original source file the error maps to for a useful diagnosis.
You may also need
Explain and Write a Regex From Plain English
Translate a plain-English matching requirement into a regex with line-by-line breakdown and edge cases.
Generate table-driven unit tests for a function with edge cases
Produces a table-driven unit test suite covering happy paths, boundaries, and error conditions for a given function.
Explain a cryptic regex and rewrite it to be readable
Decodes a confusing regex token by token, surfaces edge cases and backtracking risk, then rewrites it readably.
Decode a stack trace and pinpoint the likely root cause
Reads a stack trace frame by frame to explain the failure and pinpoint the most likely root cause with next steps.