Back to the blog

Reading an error without panicking: the anatomy of a stack trace (Python and JavaScript)

Code5 min read · 27 September 2026

The GetPack team

Your code crashes, a wall of red text shows up, and the natural instinct is to close everything and start over somewhere else. Bad idea: that wall of text, called a stack trace (or traceback in Python), almost always tells you exactly where to look. Learning to read it is the single most time-saving skill in programming, in any language.

An error is not a catastrophe

Python’s official documentation makes a useful distinction: there are syntax errors (your code isn’t even valid, Python can’t run it at all) and exceptions (your code is valid, but something goes wrong while it’s running). The second kind is “not unconditionally fatal”: they stop the program on the spot, but they exist precisely to be caught and fixed, not to punish you.

The anatomy of a Python traceback

Here’s an example, taken directly from the official documentation:

>>> 10 * (1/0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    10 * (1/0)
          ~^~
ZeroDivisionError: division by zero

Read it from the bottom up. The very last line matters most: it gives the exception type (ZeroDivisionError) and a precise message (“division by zero”). Above it, the official documentation calls this a “stack traceback”: the list of lines of code the program passed through on its way to the error, in the order they were called. In a real script with several functions calling each other, you’ll see several File "...", line X, in function_name blocks stacked up: the first corresponds to where the program started, the last one (right before the error message) to exactly where things broke.

The anatomy of a JavaScript stack trace

In JavaScript, the Error object has a stack property that does much the same thing, but in the opposite order. According to MDN, it “offers a trace of which functions were called, in what order, from which line and file,” proceeding “from the most recent calls to earlier ones.” Here’s the official example, for three functions calling each other in a chain (foo calls bar, which calls baz):

Error
    at baz (filename.js:10:15)
    at bar (filename.js:6:3)
    at foo (filename.js:2:3)
    at filename.js:13:1

This time, read it top to bottom: the first line (baz) is the function where the error actually happened, and each line after that goes back up the chain of who called whom, all the way to the original call. One thing worth remembering, straight from MDN’s beginner guide: the line number given tells you where the error showed up, not necessarily where the real cause is — sometimes the bug is a line or two earlier, in a value that was built incorrectly well before it made the program crash.

The most common beginner errors

On the Python side, a few classics, with their exact official definitions:

  • NameError: “raised when a local or global name is not found” — typically a typo in a variable name, or a variable used before it’s defined.
  • TypeError: “raised when an operation or function is applied to an object of inappropriate type” — adding a string and a number, for instance.
  • IndexError: “raised when a sequence subscript is out of range” — asking for the tenth item of a list that only has three.
  • KeyError: “raised when a mapping (dictionary) key is not found in the set of existing keys.”
  • AttributeError: “raised when an attribute reference… fails” — often a typo in a method name, or an object that isn’t the type you think it is.
  • ModuleNotFoundError: a subclass of ImportError, “raised by import when a module could not be located” — the package isn’t installed, or its name is misspelled.

On the JavaScript side, MDN’s official reference groups errors by family. The ones you’ll hit daily: TypeError (a value isn’t the expected type — typical messages: “x is not a function,” or trying to read a property on null/undefined), ReferenceError (“x is not defined,” a variable that doesn’t exist, or doesn’t exist yet, in the current scope), and SyntaxError (the code can’t even be parsed, often a missing character or parenthesis).

The method: reproduce, isolate, form a hypothesis, test, fix

Facing an error, work through it in order instead of changing code at random:

  1. Reproduce it: run the exact same action again. If the error comes back identically, you have a stable base to work from.
  2. Isolate it: cut your code down to the smallest version that still triggers the error (comment out blocks, simplify the input data) until only the essential part remains.
  3. Form a hypothesis: the exception type and the last line of the trace give you a concrete lead (“this variable is probably None at this point,” for instance).
  4. Test the hypothesis: add a check or a temporary print statement to confirm what you think is happening, before fixing anything.
  5. Fix it, then recheck: once the fix is in, rerun the whole program, not just the isolated part, to make sure nothing else broke.

Asking for help: the minimal reproducible example

Whether you’re asking an AI or posting on a forum, the quality of the answer depends directly on what you provide. Stack Overflow’s official guide defines what’s called a minimal reproducible example (also known as a reprex, an MWE, or an SSCCE depending on the community) as “a collection of source code and other data files” that lets a bug “be demonstrated and reproduced,” and that should be “as small and simple as possible” to demonstrate the problem “without additional complexity or dependencies.”

In practice, before you ask your question, prepare four things: the complete error message copied exactly as it appears (never paraphrased from memory), the smallest piece of code that still reproduces the problem, what result you expected, and what you’ve already tried. A minimal example looks something like this:

# Reliably reproduces: TypeError
price = "10"
total = price + 5

Five lines are enough here to show the problem: no need to paste your entire two-hundred-line program. A question that comes with an example like this gets answered faster, and usually better, than one that just says “it doesn’t work.”

If you’re using an AI or forum help for graded coursework, check your school’s AI usage rules first: they vary from one course to another, and it’s better to know before you hand in the assignment than after.

Key takeaways

  • A stack trace isn’t a punishment: it tells you where to look.
  • In Python, read the traceback bottom to top; the last line gives the error type and message.
  • In JavaScript, the stack property reads top to bottom, from the most recent call to the oldest.
  • The line number shows where the error appeared, not always where the real cause is hiding.
  • Debugging method: reproduce, isolate, form a hypothesis, test, fix, then recheck the whole program.
  • To ask for help: the complete error message, the minimal code that reproduces the bug, the expected result, and what you’ve already tried.

Sources

  1. Errors and Exceptions — Python documentation · accessed 27 September 2026
  2. Built-in Exceptions — Python documentation · accessed 27 September 2026
  3. JavaScript error reference — MDN · accessed 27 September 2026
  4. Error.prototype.stack — MDN · accessed 27 September 2026
  5. What went wrong? Troubleshooting JavaScript — MDN · accessed 27 September 2026
  6. How to create a Minimal, Reproducible Example — Stack Overflow Help Center · accessed 27 September 2026

Read the next article

Tools27 September 2026

Best AI for students in 2026: the honest comparison

Tools27 September 2026

New AI models in 2026: which one should you study with?

Tools27 September 2026

French AI tools you’ve never heard of: Noota, Moshi, Vibe…

Analysis27 September 2026

Why AI is so expensive (and American AI even more so)

Code27 September 2026

How to prompt an AI coding tool well: the method that changes everything

Code27 September 2026

Securing a vibe-coded app: 7 mistakes to fix before you publish

Code27 September 2026

Slopsquatting: when AI recommends packages that don't exist

Weekly brief27 September 2026

AI news roundup: the week of September 21–27, 2026

Code27 September 2026

Vibe coding: what it actually means (and how not to mess it up)

AI news27 September 2026

Why Yann LeCun wants AMI: AI beyond LLMs

Tutorial26 September 2026

Connect an MCP connector to Claude without writing a line of code

Degrees26 September 2026

Choosing your program with real MonMaster and InserSup data

Method26 September 2026

APA 7, ISO 690, Vancouver: how to cite your sources properly

Explainer26 September 2026

ChatGPT's 'hidden codes' on TikTok: fact vs. fiction

Health26 September 2026

Medicine: revise for the EDN with France's public drug database

Career26 September 2026

Internship pay and apprentice wages in 2026: the rules

Explainer26 September 2026

AI and academic integrity: what universities actually say

Tutorial26 September 2026

Installing a skill in Claude in 2 minutes

Thesis26 September 2026

Thesis: building your research question and outline with AI

Method26 September 2026

Building your exam study schedule with AI, the right way

Method26 September 2026

Revising with AI, honestly: active recall, Feynman, quizzes

Career26 September 2026

Choosing your apprenticeship with real employment data

Code27 September 2026

Learning to code in the age of AI: what you still need to know how to do yourself

Code27 September 2026

The one-page spec to write before you prompt an AI to code

Thesis27 September 2026

How to cite ChatGPT or Claude in a thesis: APA, MLA, ISO 690

Code27 September 2026

Claude Code for beginners: install, first launch, CLAUDE.md

AI news27 September 2026

Claude Opus 5.5: what really changes (and how to use it to study)

Analysis27 September 2026

The AI race: why some people are scared and others aren't

Code27 September 2026

Building your first MCP server, step by step

Code27 September 2026

Deploying your first site for free: Vercel, Netlify, Cloudflare Pages, or GitHub Pages

Explainer27 September 2026

AI detectors: are Turnitin, GPTZero and Compilatio reliable?

Code27 September 2026

Writing your own Claude skill: structure, SKILL.md, and a description that triggers

Career27 September 2026

France's national student-entrepreneur status (SNEE) and the PEPITE network, explained

Analysis27 September 2026

France in the AI race: Mistral, energy and talent

AI news27 September 2026

French Tech and AI: the French startups to know in 2026

Code27 September 2026

Git without fear: commit, branch, remote explained, then the commands that save you

Explainer27 September 2026

Chinese AI: DeepSeek, Qwen, Kimi… why Europe is wary

Health27 September 2026

AI in medical school: study for PASS, LAS and the EDN safely

Tools27 September 2026

Free AI for students: every offer and discount (2026)

Career27 September 2026

AI on an internship or apprenticeship: what’s allowed, what isn’t

Code27 September 2026

From IDE to ADE: coding with AI agents in 2026

Join GetPack

Already have an account? Sign in