Verified against GitHub Copilot Chat · 2026-07-18
Get Copilot Chat to diagnose a bug from the stack trace before it proposes a fix
A debugging prompt for the Copilot Chat panel that forces root-cause reasoning from the actual stack trace and repro steps, so the fix maps to what is really wrong instead of the first plausible guess.
The prompt
Ready to copy — highlighted parts are example details you can swap.
Diagnose this bug before proposing any fix. Do not suggest a code change until you have stated a root cause you can point to directly in the stack trace below. 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. Work in this order: 1. Walk the stack trace from the top frame down and identify exactly which line and call is throwing, in this codebase — not a generic explanation of what this error type usually means. 2. State the root cause in one sentence, naming the specific variable or condition that is wrong. 3. Only then propose the fix, as a diff, scoped to that root cause. 4. Name one other place in the codebase where the same root cause could resurface, and say whether that spot needs the same fix. If the stack trace and files given are not enough to be certain of the root cause, say exactly what additional file or log output you need instead of guessing.
Customize the highlighted detailsoptional — the prompt above already works
Why this works
Given a bare error message, Copilot Chat pattern-matches to the most common cause of that error class in general rather than this specific stack trace, because nothing forces it to actually parse the trace frame by frame before answering. Requiring the walk-through before any fix converts diagnosis into a step it cannot skip past on the way to sounding helpful. Requiring a one-sentence root cause anchored to a named variable or condition rules out the hand-wavy "there might be a null reference issue somewhere" answer that sounds diagnostic but commits to nothing checkable. Asking where else the same root cause could resurface exploits Copilot Chat's whole-file context to catch a class of bug, not just the one instance that happened to get reported. Telling it to ask for missing files instead of guessing counters the model's tendency to produce a plausible-looking fix for a wrong diagnosis when given insufficient context — the single most common way a Copilot suggestion looks right in the chat panel but does not actually address the crash that was reported.
What you get back
1. Top frame is formatRowCount at lib/reports/format.ts:34, calling .toFixed on the result of rows.length / total. 2. Root cause: total is 0 when a filtered report matches zero rows, so rows.length / total evaluates to NaN, and NaN.toFixed throws. 3. Fix: guard the division — return '0.0' directly when total === 0, before the toFixed call. 4. formatAverageValue in lib/reports/format.ts:51 has the same total-based division with no zero guard — it needs the identical fix.
Verified against
GitHub Copilot Chat Copilot Chat 1.260 (VS Code) · 2026-07-18
Changelog
- 2026-07-18 — Initial publish, verified against Copilot Chat 1.260 (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

