Find the bug from a stack trace
Works backwards from an error to a specific line and a specific cause.
You are debugging with someone who knows this codebase better than you do. Be concrete or say you cannot tell. Here is the error: ``` [PASTE STACK TRACE] ``` And the relevant code: ``` [PASTE CODE] ``` Work through it in this order: 1. Which line actually threw, and what value was it holding that it did not expect? 2. Where did that value come from? Trace it back as far as the code above allows. 3. What is the smallest change that fixes the cause rather than the symptom? 4. What else calls the same path and has the same bug right now? If the trace and the code do not line up — a version mismatch, a missing frame, minified output — say so and tell me what you need instead. Do not invent a plausible cause to have an answer.
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
Stack trace
Traceback (most recent call last):
File "report.py", line 16, in <module>
daily_report(ROWS)
File "report.py", line 10, in daily_report
print(day, round(average_paid(load_orders(rows)), 2))
File "report.py", line 6, in average_paid
return sum(paid) / len(paid)
ZeroDivisionError: division by zero
Code
def load_orders(rows):
return [{"id": r[0], "total": float(r[1]), "status": r[2]} for r in rows]
def average_paid(orders):
paid = [o["total"] for o in orders if o["status"] == "paid"]
return sum(paid) / len(paid)
def daily_report(rows_by_day):
for day, rows in rows_by_day.items():
print(day, round(average_paid(load_orders(rows)), 2))
ROWS = {
"2026-03-02": [("a1", "40.00", "paid"), ("a2", "25.50", "paid")],
"2026-03-03": [("a3", "18.00", "refunded")],
}
daily_report(ROWS)
Example output
- Line 6 threw,
return sum(paid) / len(paid). It expectedpaidto hold at least one number. The list was empty, solen(paid)was 0. paidis built on line 5 from the orders whose status is"paid". The call came fromdaily_reporton line 10. The only day inROWSwithout a paid order is 2026-03-03, whose single order is"refunded". The first day goes through and prints 32.75 before the crash.- Decide what the average of zero paid orders is, and say it in
average_paid. ReturnNonethere and letdaily_reportprint that the day had no paid orders. Dividing bylen(paid) or 1would hide the crash and print 0.0, which reads as a day of paid orders worth nothing. daily_reportis the only caller in the code you pasted. A day with an empty list of rows takes the same path and fails the same way today. I cannot see other callers ofaverage_paid, so search for them. Each one fails on a day without paid orders.
The change for point 3:
def average_paid(orders):
paid = [o["total"] for o in orders if o["status"] == "paid"]
return sum(paid) / len(paid) if paid else None
def daily_report(rows_by_day):
for day, rows in rows_by_day.items():
avg = average_paid(load_orders(rows))
print(day, "no paid orders" if avg is None else round(avg, 2))
More Coding prompts
3 of the 7 other prompts filed under Coding.
Plan a refactor before touching anything
Turns a vague urge to clean something up into an ordered, revertible sequence.
Review a diff like a senior engineer
Looks for defects and consequences, not style opinions a linter already covers.
Trace a performance problem to its cause
Separates the slow thing from the thing you noticed.
Coding tools and skills
3 of the 9 tools and 3 of the 7 skills filed under Coding, the same category as this prompt.
Continue
Open-source coding agent for VS Code, JetBrains and the CLI. Cursor acquired it, and the repository is read-only.
Cursor
An editor built around AI-assisted editing.
Devin Desktop
A full IDE with a command center for running local and cloud coding agents. It used to be called Windsurf.
Commit message writer
Writes commit messages that explain why, from the staged diff.
Pull request description writer
Writes the PR description from the branch diff, aimed at the reviewer.
Release notes writer
Writes release notes and a changelog from a commit range, leaving out the commits users never notice.
Coding guides
3 of the 6 guides filed under Coding, the same category as this prompt.
Reviewing code an AI wrote
It compiles, the tests pass, and it reads well. That combination is exactly why it needs a different kind of review.
Claude Code alternatives: agentic coding tools compared
What Claude Code needs from you today, which agents replace it in the terminal, in an editor, on your own models or in the cloud, and which of them read your SKILL.md files.
GitHub Copilot alternatives: AI coding assistants compared
What Copilot Free covers today, which tools on this index replace it in your editor, in the terminal, on your own models or across a large codebase, and the catch of each.