Triagebellfor Sentry
Guide

How to read a stack trace (JavaScript, Java, Dart, Swift)

By the Triagebell team · Updated · 4 min read · How we check guides

Short answer

A stack trace is the list of function calls that were active when an error happened, one frame per call with a file and line. In JavaScript, Java/Kotlin, Dart and Swift the most recent call is at the top, so read the error message first, then go down to the first frame that is your own code: that is usually where to fix it. In Java, also scroll to the last "Caused by:" block, which holds the root cause, and treat "... N more" as frames shared with the exception above it.

Steps

  1. Read the error lineNote the exception type and message; they often name the bug outright.
  2. Find the root cause blockIn Java and Kotlin, scroll to the last Caused by: and start there.
  3. Find your first frameGo down from the top past runtime and library frames to the first file in your code.
  4. Check the callerRead the next frame or two to see where the bad value came from.
  5. Symbolicate if neededIf frames are minified, obfuscated or hex addresses, apply source maps, mapping files or dSYMs first.

The three-step method

  1. Read the first line. The exception type and message (TypeError: Cannot read properties of undefined (reading 'id'), java.lang.IllegalStateException: …) tell you what went wrong. Many bugs are solved here.
  2. Find the first in-app frame. Skip frames from the runtime, framework and libraries (node_modules, java., android., dart:async, UIKitCore) until you hit a file you wrote. Library frames are rarely where the bug is; they show how your code was called or what it called into.
  3. Read one or two frames below it. The caller often passed the bad value. The crash line is where the symptom showed, not always where the cause is.
LanguageTop of the traceWhere the root cause usually is
JavaScript (V8, Firefox, Safari)Most recent callFirst frame in your bundle
Java / KotlinMost recent callLast Caused by: block
Dart / FlutterMost recent call (#0)First package: frame of your app
Swift (iOS crash report)Frame 0 of the crashed threadFirst frame in your binary
Python (for contrast)Oldest call (Traceback (most recent call last))The bottom
Stack trace with source context, breadcrumbs and tags of a Sentry event in Triagebell

JavaScript: frames, async and minified code

V8 (Chrome, Edge, Node.js) prints at function (file:line:column); Firefox and Safari print function@file:line:column. Both put the call that threw on top. V8 keeps 10 frames by default (Error.stackTraceLimit):

TypeError: Cannot read properties of undefined (reading 'id')
    at toRow (src/orders/table.js:42:25)
    at Array.map (<anonymous>)
    at renderOrders (src/orders/table.js:18:22)
    at async loadPage (src/orders/page.js:9:3)

Read it as: toRow at line 42, column 25 read .id on something undefined; it was called by Array.map (built-in, skip) inside renderOrders, which loadPage awaited. The at async frame is V8 stitching the trace across an await; without it the trace would stop at the event loop. Callbacks from setTimeout or event listeners start their own call chain, so the code that scheduled them is not in the trace.

In production the same trace reads at e (main.4f2a1c.js:1:48211): one line, a huge column, a one-letter name. That is minified code, and only source maps turn it back into files and lines; see Sentry source maps.

How to read a Java stack trace

The first line is the exception's toString(); each at line is a frame, most recent first. Wrapped exceptions follow as Caused by: blocks. This is the example from the Throwable documentation:

HighLevelException: MidLevelException: LowLevelException
        at Junk.a(Junk.java:13)
        at Junk.main(Junk.java:4)
Caused by: MidLevelException: LowLevelException
        at Junk.c(Junk.java:23)
        at Junk.b(Junk.java:17)
        at Junk.a(Junk.java:11)
        ... 1 more
Caused by: LowLevelException
        at Junk.e(Junk.java:30)
        at Junk.d(Junk.java:27)
        at Junk.c(Junk.java:21)
        ... 3 more

Read the last Caused by: first: LowLevelException was thrown in e() at line 30. Each layer above it caught it and rethrew a higher-level exception. ... 3 more means the remaining 3 frames are the same as the bottom 3 frames of the exception above it (here b, a, main), so the JVM doesn't repeat them. They are not lost. Suppressed: blocks, indented further, are exceptions thrown while closing resources in try-with-resources.

Kotlin on the JVM and Android prints the same format. In Android traces, frames from android., androidx., java. and kotlinx.coroutines are plumbing; look for your package name. The mistake people make next is fixing the top exception ("wrap it in another try/catch") when the bug is in the last Caused by:.

Dart and Flutter: #0 and asynchronous suspension

Dart numbers frames from #0, the most recent call, and shows the library URI, line and column. When code crosses an await, the runtime adds the frames that were waiting on it, separated by <asynchronous suspension>:

Null check operator used on a null value
#0      CartPage.build (package:acme/cart/cart_page.dart:31:28)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart)

#0      inner (package:acme/sync.dart:12:5)
<asynchronous suspension>
#1      outer (package:acme/sync.dart:20:3)
<asynchronous suspension>
#2      main (package:acme/main.dart:8:3)

Frames from package:flutter/ and dart: are the framework; your code is package:<your app>/. In the second trace, inner threw, and it was awaited by outer, which main awaited. Release builds made with --obfuscate --split-debug-info=<dir> print obfuscated names; turn them back with flutter symbolize -i <stack-trace-file> -d out/android/app.android-arm64.symbols, using the symbols file for the crashing architecture. The first trace is a classic; see null check operator used on a null value.

Swift: crashed thread, frame 0

An iOS crash report has one backtrace per thread. Find the line Thread N Crashed:; frame 0 is where it died. Each frame shows the binary, the address and, once symbolicated, the function and file:

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Thread 0 Crashed:
0   MyCoolApp   0x0000000100a71a88 @objc ViewController.viewDidLoad() (in MyCoolApp) (ViewController.swift:18)
1   MyCoolApp   0x0000000100a71a40 @objc ViewController.viewDidLoad() (in MyCoolApp) (ViewController.swift:18)
2   UIKitCore   0x00000001c569e920 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 100
3   UIKitCore   0x00000001c56a3430 -[UIViewController loadViewIfRequired] + 936

EXC_BREAKPOINT (SIGTRAP) on ARM is a Swift runtime trap: a force unwrap of nil or a failed as! on line 18 of ViewController.swift. The second column tells you whose code each frame is: your app's binary or a system framework such as UIKitCore. If you see 0x1022c0000 + 49064 instead of a function name, the report is unsymbolicated and you need the matching dSYM; see iOS crash reporting.

Stack traces in Sentry

SDKs send frames oldest to newest with an in_app flag on each, and Sentry groups errors into issues by the frames marked as your application's, so wrong flags mean bad grouping. The SDK sets defaults; you can override them per project with stack trace rules, for example stack.abs_path:**/node_modules/** -app or stack.module:com.acme.* +app. Without source maps, dSYMs, ProGuard/R8 mappings or Flutter debug symbols uploaded, Sentry shows the same minified or raw frames you would see locally.

Questions

Do you read a stack trace from the top or the bottom?

From the top in JavaScript, Java, Kotlin, Dart and Swift, where the most recent call is first. Python is the exception: its traceback is most recent call last, so start at the bottom.

What does "... 5 more" mean in a Java stack trace?

The remaining 5 frames are identical to the last 5 frames of the enclosing exception printed above, so Java leaves them out to save space.

What is an in-app frame?

A frame from your own code rather than the runtime, framework or a library. It is usually where the fix goes, and error trackers like Sentry use it for grouping.

Why does my stack trace point to line 1 of a .js file?

The file is minified, so the whole bundle is on one line. Upload source maps to see the original file, function and line.

Sources

  1. Error.prototype.stackdeveloper.mozilla.org
  2. Stack trace APIv8.dev
  3. Obfuscate Dart codedocs.flutter.dev
  4. Addressing crashes from Swift runtime errorsdeveloper.apple.com