GBot AI logoGBot AI

Understand the bug, then fix it

An error message is a clue written for experts. GBot AI translates it: what the message is saying, which line most likely caused it, and the smallest change that would prove or disprove that guess. The goal is a fix you understand, not a patch you copied.

Bring three things

The exact error text, copied rather than retyped. The code that was running. And one sentence about what you expected to happen. With those three, an explanation can point at a specific line instead of listing every possible cause.

If the error came from a test, include the test. If it only happens with some input, include an example of that input, as long as it does not contain private data.

Learn the shape of common errors

Many errors repeat across languages: using a value that does not exist yet, calling something that is not a function, reading past the end of a list, or comparing values of different types. Ask GBot AI which family your error belongs to. Once you know the family, the next error of that kind takes minutes instead of an evening.

Prove the fix

Make one change at a time and run the program again. If the error changes, read the new message: progress often looks like a different error. When it is gone, ask GBot AI how you would write a small test that would have caught it.

GBot AI does not run your code. Confirming the fix is your step, and it is the step that turns a lucky guess into understanding.

Worked example: a TypeError in three lines

A classic first bug in Python. The program asks for an age and tries to add one year.

age = input("Age: ")
print("Next year you will be " + age + 1)

# TypeError: can only concatenate str (not "int") to str
  1. Read the message literally: Python tried to join a string and a number with +, and it refuses to guess which one you meant.
  2. Find the string: input() always returns text, even when the person types 25. So age is "25", not 25.
  3. Python evaluates left to right: "Next year you will be " + age works, because both are text. Adding 1 to that text is what fails.
  4. Fix the cause, not the symptom: convert once, where the value enters the program, with age = int(input("Age: ")). Then build the message with an f-string: print(f"Next year you will be {age + 1}").
  5. Prove the fix: run it with 25, then with an empty answer. The second run raises ValueError, which tells you the next thing to handle.

Most beginner errors are a value of the wrong type or a missing value. Finding where that value was created is usually faster than staring at the line that crashed.

Example prompt

I get “TypeError: Cannot read properties of undefined (reading 'length')”. Here is the function and the line number. Explain what is undefined, why, and the smallest check that would fix it. Then suggest one test.

Questions

Can it run my code to find the bug?

No. It reasons about the code and error you provide. You run the program to confirm.

What if the explanation is wrong?

It can be. Treat the answer as a hypothesis, test it, and send back what happened. The next answer will be better with that result.

Start with GBot AI