Skip to content
AI Skill Index

Find the bug from a stack trace

Works backwards from an error to a specific line and a specific cause.

Author: Editorial
Sign in to save
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

  1. Line 6 threw, return sum(paid) / len(paid). It expected paid to hold at least one number. The list was empty, so len(paid) was 0.
  2. paid is built on line 5 from the orders whose status is "paid". The call came from daily_report on line 10. The only day in ROWS without a paid order is 2026-03-03, whose single order is "refunded". The first day goes through and prints 32.75 before the crash.
  3. Decide what the average of zero paid orders is, and say it in average_paid. Return None there and let daily_report print that the day had no paid orders. Dividing by len(paid) or 1 would hide the crash and print 0.0, which reads as a day of paid orders worth nothing.
  4. daily_report is 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 of average_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))
ShareXLinkedIn

3 of the 7 other prompts filed under Coding.

Coding tools and skills

3 of the 9 tools and 3 of the 7 skills filed under Coding, the same category as this prompt.

Tool

Continue

Open-source coding agent for VS Code, JetBrains and the CLI. Cursor acquired it, and the repository is read-only.

Open source
Tool

Cursor

An editor built around AI-assisted editing.

Freemium
Tool

Devin Desktop

A full IDE with a command center for running local and cloud coding agents. It used to be called Windsurf.

Freemium
Skill

Commit message writer

Writes commit messages that explain why, from the staged diff.

Claude Code, Cursor, Any agent
Skill

Release notes writer

Writes release notes and a changelog from a commit range, leaving out the commits users never notice.

Claude Code, Any agent

Coding guides

3 of the 6 guides filed under Coding, the same category as this prompt.

Coding

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.

Intermediate·2 min read

Cookies

We use only the cookies this site needs to work. Optional analytics helps us see which content is worth writing more of — nothing loads until you say yes.

Read the privacy policy