For developers
How to read an error message and stack trace, and debug calmly
Error messages tell you more than they seem to. Learn to read a stack trace from the right end, find the line that matters and debug step by step instead of guessing.

Reading an error message well is the fastest way to fix a bug: the message usually names the type of problem, the file, the line number and the chain of calls that led there. Beginners often skim past it and start changing code at random. Experienced developers slow down and read it properly.
This guide shows how to read an error message and stack trace, the most common error types you will meet, and a calm, repeatable debugging process that works in any language.
What does an error message tell you?
Most error messages have three parts. The error type names the category of problem, such as a TypeError, a NameError or a NullPointerException. The message describes the specific case, for example that something is undefined or a key does not exist. The location tells you the file and line where the program stopped.
Read the message literally. 'Cannot read properties of undefined (reading "name")' means you tried to use .name on something that is undefined. The question is then not 'why is name broken' but 'why is the thing before .name undefined at this point?' Rephrasing the error as a question like that is often half the fix.
Copy the exact message before you do anything else. You will want it for searching, for asking colleagues and for checking whether a change made things better or just different.
How do you read a stack trace?
A stack trace is the list of function calls that were active when the error happened. Each line, or frame, shows a function, a file and a line number. Together they show the path the program took to reach the failure.
The order depends on the language. Python prints the most recent call last, so the line that failed is at the bottom, just above the error message. JavaScript and Java print the most recent call first, at the top. Check which end you are looking at before you start.
Many frames will belong to libraries or the language runtime. Skip those and look for the first frame in your own code, nearest the failure. That is usually where your mistake is, or where bad data first entered the code that failed.
The question is not why is it broken, but why is this value wrong at this point.
Which errors come up most often?
Names differ between languages, but the same families of errors appear everywhere. Recognising them saves time.
- Syntax errors: a missing bracket, quote or colon. The reported line may be just after the real mistake.
- Name or reference errors: a variable or function that does not exist, often a typo or a missing import.
- Type errors: an operation on the wrong kind of value, such as adding a number to text or calling something that is not a function.
- Null or undefined errors: using a value that is empty, often from a failed lookup or a missing API field.
- Index or key errors: asking for a list position or dictionary key that is not there.
- Import or module errors: a missing dependency, wrong path or wrong environment.
- Permission and file errors: a path that does not exist or cannot be accessed.
What is a calm, repeatable way to debug?
Random edits make bugs harder to find, because you lose track of what changed. A simple process keeps you in control.
- Reproduce the error reliably, with the smallest input that triggers it.
- Read the full message and find the first stack frame in your own code.
- Form a guess: what value would have to be wrong for this line to fail?
- Check the guess by printing or logging the value, or by pausing in a debugger.
- Work backwards to where the wrong value came from.
- Change one thing at a time and re-run after each change.
- Once fixed, add a test that would have caught it.
When should you use a debugger instead of print statements?
Printing values is quick and works everywhere, and plenty of experienced developers rely on it. It becomes slow when you need to inspect many values or step through a loop, because each new question means editing and re-running the code.
A debugger lets you set a breakpoint on a line, run the program until it reaches that line, then inspect every variable, step forward one line at a time and walk up the call stack. Most code editors include one, and languages such as Python ship with a built-in debugger you can start from code. Learning the basic controls (continue, step over, step into, step out) pays off quickly.
How do you search for an error and ask for help well?
Search for the error type and the general part of the message, leaving out your own file names, variable names and values. Add the language or library name. Official documentation and issue trackers for the library involved are usually more reliable than random snippets.
When you ask a colleague or a forum, include the full error and stack trace as text, the smallest piece of code that reproduces it, what you expected to happen, and what you have already tried. Writing that out often reveals the answer before you send it. Explaining the problem line by line to someone, or even to a rubber duck on your desk, works for the same reason.
Frequently asked questions
Why does the error point to the wrong line?
+
With syntax errors, the parser often notices the problem only on the line after the real mistake, such as a missing bracket. With runtime errors, the line is correct but the bad value may have been created earlier. Look a little above and trace where the value came from.
What is a traceback in Python?
+
A traceback is Python's name for a stack trace. It lists the calls leading to the error with the most recent call last, followed by the error type and message on the final line.
What is the difference between an error and a warning?
+
An error stops the program or the build. A warning reports something suspicious but lets the program continue. Warnings are worth fixing because they often point to future bugs.
What is rubber duck debugging?
+
It means explaining your code out loud, line by line, to an object such as a rubber duck. Putting the logic into words often reveals the mistake without anyone else's help.
How do I debug code that does not show an error?
+
Compare what the program does with what you expected at each step. Log or inspect values at key points until you find where actual and expected first differ. Then focus on that spot.
Should I paste error messages into an AI chat assistant?
+
It can help explain unfamiliar messages. Remove secrets, keys and personal data first, and check any suggested fix by understanding why it works rather than pasting it in blindly.
Next time something breaks, resist the urge to start editing. Read the message, find your first frame in the stack trace, ask what value must be wrong, and check it. Calm debugging is faster debugging.
How we research: Guides are written from established sources and checked for accuracy. They are general information, not professional advice.
Written by
Cursorlane Editorial Team
Software & tools
Our writers are developers and heavy software users who test what they write about and update guides when the tools change.


