← IndexEntry № 012·coding

Debug an Error Message Step-by-Step

Get a structured debugging plan: error explanation, ranked root causes, tests, and fixes.

Optimized for
ClaudeChatGPT
§ When to use this

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.

§ The Prompt— fill in the fields, then copy or open in a tool
§ Customize0/3 fields filled
your prompt — fill the fields above
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]
Open with your prompt →ChatGPTClaudeSends your filled-in prompt straight into a new chat.
§ Example Output

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.

§ Pro Tips

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.
§ Variations

Adapt it for your case

Stack-trace triage only

Ask just for steps 1 and 2 (explanation and ranked causes) when you want a fast read before deciding whether to dig in.

Production incident mode

Add logs and metrics alongside the error and ask it to factor in timing, deploys, and traffic when ranking causes.

Teach-me-while-fixing

Append 'For each cause, explain the underlying concept so I recognize this class of error next time.'

Use For — Tasks
Tags#debugging#coding#errors
§ FAQ

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.

§ Related Entries

You may also need