Verified against GitHub Copilot Chat · 2026-07-29
Make Copilot Chat trace a stack frame to a root cause before it proposes a fix
A diagnosis-first debugging prompt that walks Copilot Chat down the actual stack trace, frame by frame, and requires a named root cause before any fix is proposed, so the fix addresses what is really wrong rather than the first plausible-looking cause.
The prompt
Ready to copy — highlighted parts are example details you can swap.
Diagnose this before proposing anything. I do not want a fix suggestion until you have walked the stack trace below and named a root cause you can point to directly in it. ERROR TypeError: Cannot read properties of undefined (reading 'toFixed') STACK TRACE at formatRowCount (lib/reports/format.ts:34:18) at ReportSummary (components/reports/ReportSummary.tsx:19:22) HOW TO REPRODUCE Open any report, filter the date range so zero rows match, then view the summary panel. RELEVANT FILES lib/reports/format.ts and components/reports/ReportSummary.tsx, pasted below. WHAT HAS ALREADY BEEN TRIED Tried adding a loading state around ReportSummary — the crash still happens once loading finishes and zero rows render. WORK THROUGH THIS IN ORDER 1. Start at the top frame of the stack trace and go down it one frame at a time, stating in this codebase specifically — not a generic description of what this error class usually means — which line is throwing and what it was doing when it threw. 2. Identify the specific variable, argument, or condition that was actually wrong at that point, named precisely, not a category like 'a null reference issue' — name the exact thing and its actual value or state at the moment of failure. 3. Trace that wrong value back one more step: where was it supposed to be set correctly, and what about Open any report, filter the date range so zero rows match, then view the summary panel. caused it not to be. If the trail goes further back than one step, follow it until you reach something that is either clearly the actual origin or clearly outside what lib/reports/format.ts and components/reports/ReportSummary.tsx, pasted below. can show you — and say explicitly which of those two you hit. 4. Only now propose the fix, scoped exactly to the root cause identified in steps 2 and 3, as a diff — not a broader cleanup of the surrounding code that was not shown to be part of the problem. 5. Name one other place in the codebase where the same root cause — the same wrong assumption about a value's shape or presence — could plausibly resurface, and say whether that place needs the same fix or is already protected against it. IF Tried adding a loading state around ReportSummary — the crash still happens once loading finishes and zero rows render. DID NOT WORK Say specifically why the earlier attempt did not fix this, based on what the stack trace above actually shows — not a vague 'that approach was on the right track but incomplete.' If the earlier attempt addressed a real but different problem than the one this trace shows, say so plainly rather than treating it as a partial success. IF THE TRACE AND FILES GIVEN ARE NOT ENOUGH Say exactly what additional file, log line, or piece of state you would need to be certain of the root cause, rather than proposing a fix built on a guess dressed up as a diagnosis.
Customize
Optional — swap in your own details for the highlighted parts above.
Why this works
Given a bare error message, Copilot Chat's fastest path to a plausible-sounding answer is pattern-matching to the most common cause of that error class in general, because nothing in an unstructured question forces it to actually parse this stack trace frame by frame before answering — a generic explanation of what a null reference or a type mismatch usually means is a real answer to a different, easier question than the one that was actually asked. Requiring the frame-by-frame walk before any fix converts diagnosis from something Copilot could skip past on the way to sounding helpful into a step with a checkable output: a specific line, in this codebase, doing a specific thing. Naming the exact variable or condition, rather than accepting a category-level answer, closes off the single most common way a debugging answer sounds diagnostic while committing to nothing a reviewer could actually verify against the trace — there might be a null reference somewhere cannot be wrong in a way anyone can point to, while total was zero at line 34 can be checked in ten seconds against the pasted code. Tracing the wrong value back one further step, rather than stopping at the line that threw, targets the gap between where an error surfaces and where it actually originates, which are frequently two different lines or even two different files — fixing only the symptom line without understanding the origin produces a patch that suppresses this specific crash while leaving the actual wrong assumption intact somewhere upstream, ready to surface differently the next time the input varies slightly. Checking a failed prior attempt against what the trace actually shows, rather than treating it charitably as on the right track, matters because an AI assistant asked to build on a previous fix has a real incentive to find some truth in it rather than contradict a human's earlier effort outright, and that incentive is exactly backwards when the earlier attempt solved a different, adjacent problem rather than a partial version of this one. Finally, instructing it to ask for missing files rather than guess counters the tendency of any diagnosis-then-fix flow to produce a fix that looks complete under insufficient context — the single most common way a Copilot Chat suggestion looks right in the panel but does not actually address the failure that was reported.
What you get back
1. Top frame is formatRowCount at lib/reports/format.ts:34, calling .toFixed on rows.length divided by total. 2. total is 0 when a filtered report matches zero rows, making the division NaN, and NaN.toFixed throws. 3. Fix: guard the division, returning a fixed zero value directly when total is zero. 4. formatAverageValue in the same file has the identical unguarded division — it needs the same fix.
Verified against
GitHub Copilot Chat Copilot Chat 1.269 (VS Code) · 2026-07-29
Changelog
- 2026-07-29 — Initial publish, verified against Copilot Chat 1.269 (VS Code).
Need this built into your business?
If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.
EXPLORE CUSTOM SOFTWARE
