Skip to content
  1. LuzineDebug
  2. Guides
  3. How to read a stack trace (JS, Python, PHP, Java…
Guide Beginner ≈ 10 min

How to read a stack trace (JS, Python, PHP, Java)

In short

Read a stack trace in three passes: the error type and message, the reading direction of the language, then the first frame that points to your own code. In Python the failing line is at the bottom; in JavaScript, PHP and Java it is at the top. If the trace contains "Caused by", the root cause is the last one.

Be the first to approve this guide

Why this method

A stack trace (call stack) is the list of functions that were running when the error was thrown, each with its file and line. It is the most valuable piece of information in a crash, but it often looks scary: dozens of lines, library paths, nested errors. With a simple method you will find the useful line in under a minute, whether the error comes from Node.js, the browser, Python, Laravel or a Java application.

What you need

  • A complete stack trace, copied as text (not a screenshot)
  • The project source code open in your editor
  • For minified code: the source maps generated by the build

Step by step

  1. Read the type and message first

    Before looking at the frames, read the exception type (TypeError, KeyError, NullPointerException, QueryException) and its message. They tell you what: a missing value, an absent key, a refused connection. The lines below only tell you where.

    In JavaScript, PHP and Java the message is on the first line. In Python it is on the last line of the trace. Copy that exact message: it is also what you will paste into a search engine or the error analyzer.

  2. Know the reading direction of the language

    Each language stacks calls in a specific order. In JavaScript (V8), each at function (file:line:column) line starts where the error was thrown, then goes up to the callers. Java follows the same logic with at package.Class.method(File.java:42). In PHP, the in file.php:12 line gives the throw point, then frames #0, #1… go up the callers. In Python, the header Traceback (most recent call last) warns you: the most recent call is at the bottom, right above the message.

    plaintext
    # Node.js : la ligne fautive est la PREMIÈRE frame
    TypeError: Cannot read properties of undefined (reading 'total')
        at computeCart (/app/src/cart.js:14:22)
        at handler (/app/src/routes/cart.js:8:10)
        at Layer.handle (/app/node_modules/express/lib/router/layer.js:95:5)
    
    # Python : la ligne fautive est la DERNIÈRE frame
    Traceback (most recent call last):
      File "/app/main.py", line 20, in <module>
        run()
      File "/app/main.py", line 12, in run
        print(user["email"])
    KeyError: 'email'
  3. Find the first frame of YOUR code

    A trace mixes your code with library code. Walk it in the reading direction and stop at the first line whose path belongs to your project. Skip paths that contain node_modules/, node:internal, site-packages/, vendor/, java.base/ or org.springframework.

    The library is almost never at fault: it simply received a value from your code that it could not handle. The line of your code just before entering the library is the one that passed the wrong argument.

    In PhpStorm and VS Code, paste the trace into the console: the paths become clickable.

  4. Go down to the root cause

    When an error is caught and rethrown as another one, the trace contains several blocks. In Java, each Caused by: is a deeper cause: the last one is the root cause, and ... 23 more means the remaining frames are identical to the previous block. In Python, look for "The above exception was the direct cause of the following exception": the cause is the upper block. In PHP, previous exceptions appear after Next. In Node.js, an error created with { cause } prints its cause under [cause].

    plaintext
    org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC Connection
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:277)
        ...
    Caused by: java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.connect0(Native Method)
        ... 42 more
  5. Handle async and truncated traces

    In JavaScript, an error inside a callback (setTimeout, event, old callback API) loses the original caller: the trace stops at the event loop. With async/await, V8 rebuilds the chain and prints at async function lines. So prefer await over nested .then() calls.

    V8 also limits the trace to 10 frames by default. Raise the limit to see the whole stack, and enable source maps if your code is compiled (TypeScript, bundler).

    bash
    node --stack-trace-limit=50 --enable-source-maps dist/server.js
  6. Translate minified code

    In production, the browser often shows main.4f9a1c.js:1:28934: a single huge unreadable line. Chrome and Firefox DevTools apply source maps automatically when the .map file is reachable, and then show the real file and line. Otherwise, use the {} (pretty print) button to reformat the code. On the server side, Sentry or a similar tool can receive the source maps without making them public.

  7. Check your hypothesis on the line you found

    Open the file at the given line and ask which value could produce that message. Add a console.log, a print, a dump() or better a breakpoint just before it, then reproduce the error. If the value is already wrong at that point, move up one frame in the trace: you are following the data back to the place where it became incorrect.

Mistakes to avoid

  1. Reading a Python trace top to bottom: the first frame is the program entry point, the real error is at the bottom.
  2. Blaming the library: an error inside node_modules or vendor almost always comes from a wrong argument passed by your code.
  3. Stopping at the first block: the visible exception often wraps the real cause, hidden under Caused by or Next.
  4. Sharing a cropped screenshot: without the full text, neither you nor anyone else can follow the stack.

Checklist

Did this guide help you?

Approve it in one click: it will be highlighted for other developers.

Frequently asked questions

What is a stack trace?

It is the list of function calls in progress when the error happened, each with its file and line. It shows the path the program took up to the crash.

Why does my stack trace point to node_modules or vendor?

Because the error was thrown inside a library. Keep reading until the first line of your project: that is the call that gave the library an unexpected value.

How do I show a full stack trace in Node.js?

Start Node with --stack-trace-limit=50 or set Error.stackTraceLimit = 50 at startup. Add --enable-source-maps to get TypeScript line numbers back.

What does "... 23 more" mean in a Java trace?

The next 23 frames are identical to those of the previous block. Java hides them to keep the trace short: nothing is lost.

Tools to apply this guide

More guides