DebugAIdocs

Your first debug

A three-file project with a planted bug, where the line that crashes is not the line that is wrong. Watch DebugAI trace it.

Most bugs worth a debugger do not sit on the line that crashes. This one does not either. The traceback points at one file, and the mistake is in another file it never names. Setting it up takes three files and uses one of your 10 free debugs.

Do the VS Code quickstart first, as far as signing in. If you use an agent instead, see With an agent below. Pick a language once and every step below follows it.

Create the project

Make an empty folder called first-bug and open it in your editor with File, Open Folder. Add these three files:

settings.py
# Shop settings. In a real app these come from the environment.
TAX_RATE = "0.08"
FREE_SHIPPING_OVER = 50
cart.py
from settings import TAX_RATE, FREE_SHIPPING_OVER


def subtotal(items):
    return sum(item["price"] * item["qty"] for item in items)


def total(items):
    sub = subtotal(items)
    shipping = 0 if sub >= FREE_SHIPPING_OVER else 5
    return round(sub * (1 + TAX_RATE) + shipping, 2)
main.py
from cart import total

items = [
    {"name": "keyboard", "price": 49.0, "qty": 1},
    {"name": "cable", "price": 6.5, "qty": 2},
]
print(f"Total: {total(items)}")

Index it

Run DebugAI: Index Entire Workspace. It should report Indexed 3 files. This is the step that matters here: the traceback in the next step never names the file with the mistake in it, so without the index DebugAI has no way to read it.

Run it

In the editor's terminal:

python main.py
Traceback (most recent call last):
  File ".../first-bug/main.py", line 7, in <module>
    print(f"Total: {total(items)}")
                    ^^^^^^^^^^^^
  File ".../first-bug/cart.py", line 11, in total
    return round(sub * (1 + TAX_RATE) + shipping, 2)
                        ~~^~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'

On some systems the command is python3.

Ask DebugAI

Right-click inside the terminal, pick DebugAI: Analyze Terminal Error, then Analyze This.

Read the answer

The crash is in cart.py, line 11. The cause is settings.py, line 2: TAX_RATE is the string "0.08", not the number 0.08. That is what the Root Cause should name.

A fix that wraps TAX_RATE in float() inside cart.py would also stop the crash. It treats the symptom: every other file that imports TAX_RATE breaks the same way. A fix in settings.py treats the cause.

Apply it and run again

Press Preview & Apply Fix on the fix that treats the cause, check the diff, and press Apply. Then run the program again:

Total: 66.96

What just happened

DebugAI read the traceback, then searched your index for the code behind it. That search is how an answer can reach a file the traceback never names. The fix you applied is recorded with the error, so if the same error comes back in this project, the panel says so with a Fixed before badge. See Error memory.

With an agent

Open the first-bug folder in your agent (setup) and ask:

Run python main.py. If it fails, use DebugAI to find the root cause before you change anything.

For JavaScript, ask it to run node main.js instead. The npm server has no index step: it reads the files the stack trace names, up to three, from inside the project. If the answer stops at the file that crashed, ask your agent to pass DebugAI the file the import comes from.

In ChatGPT or Codex, paste the three files and the traceback, then ask it to debug with DebugAI. The plugin cannot read your files, so it only knows what you paste.

Next

On this page