• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tool for decrypting stack traces coming from the minified JS code.

stack-beautifier

Tool for decrypting stack traces coming from the minified JS code.

wat?

This tool helps with translating minified/uglified stack traces from your production apps (NodeJS/react native/web) into a human readable form (with line number from your original source files) utilising the concept of source maps. This tool aims at providing a simple way of deminifying stack traces from a command line interface as opposed to other great existing alternatives, which provides similar functionality but require integration into a deployment process.

Installation

Install it using npm: npm install -g stack-beautifier

Usage

By default the tool accepts source map file as an argument and reads stack trace from the standard input and the prints out the translated stack trace to the standard output. The default behaviour can be altered by using the following command line options:

  Usage: stack-beautifier [options] <app.js.map>

  Options:

    -t, --trace [input_file]    Read stack trace from the input file (stdin is used when this option is not set)
    -o, --output [output_file]  Write result into the given output file (stdout is used when this option is not set)
    -l, --long                  Output complete javascript filenames in the stacktrace (tool will try to shorten file paths by default)

Stack trace input format

The tool can understand javascript stack traces that starts with a single line of error message followed by many lines each representing a single stack trace level. The line format has been made compatible with what you can get from most popular JS engines (V8 and JSC used in React-Native). Here are a few examples of stack traces the tool can understand:

V8 stack trace:

TypeError: Assignment to constant variable.
    at <anonymous> (app.bundle.js:34:612)
    at b (app.bundle.js:11:3018)
    at d (app.bundle.js:8:1074)
    at <anonymous> (app.bundle.js:1:5)

JSC (react-native) stack trace:

Fatal Exception: com.facebook.react.common.JavascriptException: Invalid attempt to destructure non-iterable instance, stack:
<unknown>@9:487
o@781:121
value@80:1312
value@42:1514
<unknown>@18:912
d@31:10
value@11:1512

Using with React Native

When using react-native, javascript bundle gets created as a part of the release build process (unless you use react-native-code-push or similar tooling). We recommend that you alter that build step to also generate a source map that you can archive somewhere and then use for decrypting stack traces when necessary.

To do so on android you can add the following snippet to your android/app/build.gradle:

project.ext.react = [
    extraPackagerArgs: ['--sourcemap-output', file("$buildDir/outputs/index.android.js.map")]
]

Note that it has to be added before the apply from: "../../node_modules/react-native/react.gradle" line. After a successful build the sourcemap will be located under android/app/build/outputs/index.android.js.map.

Generate source map from the application sources

If you don't have access to the source map file there is still hope. You can checkout the version at which the bundle has been generated and run the following command for android:

react-native bundle --platform android --entry-file index.js --dev false --reset-cache --bundle-output /tmp/bundle.android.js --assets-dest /tmp/ --sourcemap-output index.android.js.map

or for iOS:

react-native bundle --platform ios --entry-file index.js --dev false --reset-cache --bundle-output /tmp/bundle.ios.js --assets-dest /tmp/ --sourcemap-output index.ios.js.map

Note that it is crutial that all the dependencies from node_module are at the same version as when the JS bundle has been generated, otherwise the source map may not give you the correct mapping. We recommend using yarn that helps in ensuring reproducable JS bundle builds.

Example usage:

In order to use this tool you first need to have access to the source map file associated with the javascript bundle you're getting the stack trace from. Assume that the sourcemap is stored in app.js.map file and the stack trace is save in mytrace.txt and looks as follows:

Fatal Exception: com.facebook.react.common.JavascriptException: Invalid attempt to destructure non-iterable instance, stack:
<unknown>@9:487
o@781:121
value@80:1312
value@42:1514
<unknown>@18:912
d@31:10
value@11:1512

Now you can call the following command in order to get the deminified stack trace printed:

 > stack-beautifier app.js.map -t mytrace.txt
Fatal Exception: com.facebook.react.common.JavascriptException: Invalid attempt to destructure non-iterable instance, stack:
  at arr (./node_modules/react-native/packager/react-packager/src/Resolver/polyfills/babelHelpers.js:227:22)
  at _url$match (./js/launcher/index.js:9:30)
  at _currentSubscription (./node_modules/react-native/Libraries/EventEmitter/EventEmitter.js:185:11)
  at ./node_modules/react-native/Libraries/Utilities/MessageQueue.js:273:27
  at __callImmediates (./node_modules/react-native/Libraries/Utilities/MessageQueue.js:119:11)
  at fn (./node_modules/react-native/Libraries/Utilities/MessageQueue.js:46:4)
  at __callFunction (./node_modules/react-native/Libraries/Utilities/MessageQueue.js:118:20)

Troubleshooting

Getting error "Stack trace parse error at line N"

It means that the tool is not able to understand the format of the stacktrace. The tool only supports most common stack traces formats, please check if the stack trace you're trying to input is in one of the supported formats. There is also a chance that your stack trace is in a valid format but your file contain some

Still having some issues

Try searching over the issues on GitHub here. If you don't find anything that would help feel free to open new issue!

Contributing

All PRs are welcome!

More Repositories

1

reanimated-2-playground

Playground app – fresh React Native project with preinstalled Reanimated v2
Java
186
star
2

react-native-swiftui

JavaScript
177
star
3

react-native-url-router

A new way to create navigation in react-native
TypeScript
132
star
4

react-native-turbo-demo

React Native Turbo - an open source library that can bring your turbo-enabled web application into the React Native world.
Kotlin
105
star
5

expo-maps

Swift
81
star
6

react-native-resource-saving-container

View container that saves resources (bitmaps, camera) by detaching native views when they are not visible
JavaScript
80
star
7

drawings-and-animations-workshop

TypeScript
64
star
8

gradient-shared-transitions-example

JavaScript
44
star
9

elixir-caldav-client

CalDAV client in the Elixir language
Elixir
41
star
10

react-native-hour-format

Get hour format from OS settings.
Java
28
star
11

reanimated-bottom-sheet-video

JavaScript
27
star
12

web3-account

Adapter application for consuming web3 messages from ie. wallets, and passing them on to starknet
TypeScript
20
star
13

react-native-docker-android

Docker image for building React Native apps for Android in clear environment
Dockerfile
18
star
14

react-native-labs

Directory with experimental React Native modules and features
Java
16
star
15

detox-your-graphql

Example app for E2E testing with Detox and Apollo GraphQL Server
JavaScript
14
star
16

react-native-memory-leak-example

Example app that demonstrates how resources could be leaked in React Native apps
JavaScript
11
star
17

appjs-2023-workshop-reanimated

TypeScript
11
star
18

tinymceMathjax

MathJax plugin for tinyMCE v4
HTML
10
star
19

elixir-janus

Bindings for Janus Gateway for the Elixir language
Elixir
10
star
20

elixir-ibm-speech-to-text

Elixir client library for IBM Cloud Speech to Text service
Elixir
8
star
21

appjs-2023-workshop-expo-modules

TypeScript
6
star
22

poke-workshops

Workshops for teaching React Native and Expo
JavaScript
6
star
23

scarb-eject

Create cairo_project.toml for a given Scarb package.
Rust
5
star
24

starknet-android-demo

Kotlin
5
star
25

appjs-2024-workshop-optimization-start

TypeScript
5
star
26

EIP712-cairo-article

Cairo
4
star
27

elixir-gcloud-speech-grpc

Elixir client for Google Cloud Speech-to-Text API using gRPC
Elixir
4
star
28

intro-to-blockchain

Python
4
star
29

protostar-tutorial

Cairo
4
star
30

elixir-janus-transport-ws

Elixir
4
star
31

appjs-2022-workshops-start

Everything you need to know about Fabric and JSI
Java
4
star
32

elixir-janus-plugin-videoroom

Bindings for Janus Gateway for the Elixir language - videoroom plugin API
Elixir
4
star
33

reanimated-parallax

JavaScript
4
star
34

react-native-android-jsc-debugging

Proof of concept for connecting remote debugger to RN's JSC running on Android
Ruby
3
star
35

appjs-2023-workshop-optimization-start

TypeScript
3
star
36

react-native-ai-tutorial

TypeScript
3
star
37

crypto-cpp-py

Python packaged crypto-cpp
Python
3
star
38

workshops-crypto

Python
2
star
39

starknet-workshops-ethwarsaw

Cairo
2
star
40

expo-workshops-agh-2018

Code from SoftwareMansion workshops for AGH UST 2018
JavaScript
2
star
41

expo-workshops

JavaScript
2
star
42

poseidon-py

Poseidon hash Python library
Python
2
star
43

elixir-sftp-toolkit

SFTP Toolkit library for Elixir
Elixir
2
star
44

executorch-style-transfer

Demo app for executorch style transfer tutorial.
C++
2
star
45

reanimated-beta-docs

New Reanimated Documentation
JavaScript
1
star
46

elixir-guerilla

Elixir
1
star
47

eslint-config-swmansion

SoftwareMansion's eslint config
JavaScript
1
star
48

rnos-library-matrix-tester

Run E2E tests of SWM libraries on different versions of React Native and across various configurations.
TypeScript
1
star
49

protostar-workshop-2023

1
star
50

dobra-noc-recorder

Elixir
1
star
51

janus_experiments

Experiments with Janus API
Python
1
star
52

babel-plugin-animated-block

Babel plugin to simplify RN animated expression
Objective-C
1
star
53

reanimated-legacy-docs

Legacy Reanimated Documentation
JavaScript
1
star
54

pokedex

πŸ“• PokΓ©dex πŸ“• in React Native with use of GraphQL πŸ“ DIY workshop πŸ› 
JavaScript
1
star
55

grafana-backup-s3

Tool for backing up & restoring Grafana dashboards and data sources and uploading them to S3 bucket.
Python
1
star
56

elixir-xattr

Elixir library for accessing and manipulating custom extended filesystem attributes
C
1
star