GBot AI logoGBot AI

How to read an error message (and stop fearing stack traces)

Published by GBot AI on 20 November 2026. Updated 30 November 2026.

Beginners often scroll past error messages and paste the whole thing somewhere asking “why doesn’t this work?”. The message usually already says what went wrong and where. Once you know how to read it, most errors take minutes instead of hours. This guide breaks an error into its parts and shows how to use GBot AI when you are stuck.

The three parts of almost every error

First, the type, such as TypeError, NameError, SyntaxError, or NullPointerException. The type tells you the family of problem. Second, the message, a short sentence such as “cannot read properties of undefined” or “name ‘total’ is not defined”. Third, the location: a file name and line number, often followed by a list of other locations called the stack trace.

Read them in that order. The type narrows the cause, the message names it, and the location tells you where to look.

Find your line in the stack trace

A stack trace lists the chain of function calls that led to the error. Some lines belong to libraries and frameworks, and some belong to your code. Look for the first line that points to a file you wrote. That is usually where the bug is, even if the error was raised deeper inside a library.

In Python the most recent call is at the bottom. In JavaScript and Java it is at the top. Knowing that saves a lot of confusion.

Translate the message into a question

“Cannot read properties of undefined (reading ‘length’)” becomes “what is undefined on this line, and why did I expect it to have a length?” “Index out of range” becomes “how long is the list here, and which index did I ask for?” A question like that points you at one variable to inspect.

Print or log that variable just before the failing line and run the program again. Seeing the real value often solves the bug immediately.

When to ask GBot AI, and how

If you have read the message, found your line, and still do not know why the value is wrong, ask. Paste the full error, the function it points to, and what you expected. Ask for an explanation of the error family and the smallest fix, not a rewrite.

Then apply the fix yourself and run the program again. If a new error appears, that is often progress: read the new message the same way.

Example: reading a Python traceback from the bottom up

Stack traces look long, but you only need two lines to start. Here is a short one.

Traceback (most recent call last):
  File "app.py", line 14, in <module>
    main()
  File "app.py", line 10, in main
    send_receipt(load_user(42))
  File "app.py", line 6, in send_receipt
    print("Sending to", user["email"].lower())
KeyError: 'email'
  1. Start at the last line. The type is KeyError and the detail is 'email': the code asked a dictionary for a key it does not have.
  2. Go up one frame to find the line that failed: app.py, line 6, in send_receipt, the user["email"] lookup.
  3. Keep going up to see where the value came from: line 10 passed in load_user(42). So the question becomes “why does user 42 have no email?”, not “why is line 6 broken?”
  4. Turn that into a check: print the user returned by load_user(42), or ask GBot AI to explain the traceback with load_user pasted alongside.
  5. Decide the real fix: either the data is wrong, or the code must handle users without an email, for example with user.get("email") and a clear message.

Bottom line first, then your own files from the top down. Library frames in between can usually be skipped on the first read.

Example prompt

Here is my Python error and the function on line 14. Which part of the message tells me the cause? Explain the error type, what is wrong on that line, and the smallest fix.

Questions

Why does the error point to a library file instead of my code?

The library is where the problem was noticed, not where it started. Look further along the stack trace for the first line in your own files.

Should I just search the error online?

Searching the type and message (without your file names) is a good habit. If the results do not match your situation, an explanation based on your actual code helps.

Start with GBot AI