metro
metro copied to clipboard
npx metro-symbolicate returns TypeError: Line must be greater than or equal to 1, got 0
Downloaded a minified hermes crash log from Crashlytics
Tried the following command: npx metro-symbolicate <path/to/sourcemapfile> < stacktrace.txt
Error: TypeError: Line must be greater than or equal to 1, got 0
info Fetching system and libraries information... System: OS: macOS 13.1 CPU: (8) arm64 Apple M2 Memory: 113.50 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node Yarn: 1.22.19 - ~/repos/aph-mobile-patients/node_modules/.bin/yarn npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm Watchman: 2023.04.10.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/ashishkumar/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 Android SDK: Not Found IDEs: Android Studio: 2022.1 AI-221.6008.13.2211.9619390 Xcode: 14.3/14E222b - /usr/bin/xcodebuild Languages: Java: 11.0.18 - /usr/bin/javac npmPackages: @react-native-community/cli: ^4.5.1 => 4.14.0 react: ^18.2.0 => 18.2.0 react-native: 0.68.0 => 0.68.0 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
@itsashis4u
Remove all stack trace lines starting with first line containing "[native code]" as the "[native code]" seems to cause problems.
And also remove lines contains ":0:0" as well.
This has fixed my issue.
I also ran into this with stack traces copied from Crashlycs, but for me the stack traces for Android worked fine and the iOS stack traces did not.
I removed the lines that included :0:0
as @mparyani445 suggested. This allowed metro-symbolicate to execute without error. However, the results were not correct. I noticed that the lines in the iOS stack traces included a duplicate element at the end. When I deleted the last delimiter and last number for each line of the trace, metro-symbolicate produced correct results.
For example, I changed (main.jsbundle:1066:119:1066)
to (main.jsbundle:1066:119)
. It's possible the greedy nature of the regex in metro-symbolicate is thrown off by the extra value.
Here is my original iOS stack trace from Crashlytics that caused metro-symbolicate to fail with the error reported by @itsashis4u:
Non-fatal Exception: JavaScriptError
0 ??? 0x0 <unknown> (apiWithRetrySaga exceeded retries)
1 ??? 0x0 t + 1066 (main.jsbundle:1066:119:1066)
2 ??? 0x0 <unknown> + 1066 (main.jsbundle:1066:387:1066)
3 ??? 0x0 <unknown> + 1028 (main.jsbundle:1028:8462:1028)
4 ??? 0x0 u + 63 (main.jsbundle:63:157:63)
5 ??? 0x0 <unknown> + 63 (main.jsbundle:63:866:63)
6 ??? 0x0 k + 70 (main.jsbundle:70:513:70)
7 ??? 0x0 w + 70 (main.jsbundle:70:911:70)
8 ??? 0x0 callReactNativeMicrotasks + 70 (main.jsbundle:70:3067:70)
9 ??? 0x0 <unknown> + 33 (main.jsbundle:33:2872:33)
10 ??? 0x0 <unknown> + 33 (main.jsbundle:33:1108:33)
11 ??? 0x0 <unknown> + 33 (main.jsbundle:33:2532:33)
12 ??? 0x0 <unknown> + 33 (main.jsbundle:33:1067:33)
13 ??? 0x0 <unknown> ([native code]:0:0)
14 ??? 0x0 <unknown> ([native code]:0:0)
Here is the output after removing the last two lines containing :0:0
lines. metro-symolicate ran to completion, but the results are not accurate:
Non-fatal Exception: JavaScriptError
0 ??? 0x0 <unknown> (apiWithRetrySaga exceeded retries)
1 ??? 0x0 t + 1066 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js:27:<global>)
2 ??? 0x0 <unknown> + 1066 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/Vibration/NativeVibration.js:23:<global>)
3 ??? 0x0 <unknown> + 1028 (null:null:null)
4 ??? 0x0 u + 63 (/Users/dave/Projects/cea-native/node_modules/@react-native/assets/path-support.js:17:<global>)
5 ??? 0x0 <unknown> + 63 (/Users/dave/Projects/cea-native/node_modules/lodash/_memoizeCapped.js:15:memoizeCapped)
6 ??? 0x0 k + 70 (null:null:null)
7 ??? 0x0 w + 70 (/Users/dave/Projects/cea-native/node_modules/lodash/_baseMatches.js:14:baseMatches)
8 ??? 0x0 callReactNativeMicrotasks + 70 (null:null:null)
9 ??? 0x0 <unknown> + 33 (null:null:null)
10 ??? 0x0 <unknown> + 33 (null:null:null)
11 ??? 0x0 <unknown> + 33 (null:null:null)
12 ??? 0x0 <unknown> + 33 (null:null:null)
And here is the fully modified input stack trace:
Non-fatal Exception: JavaScriptError
0 ??? 0x0 <unknown> (apiWithRetrySaga exceeded retries)
1 ??? 0x0 t + 1066 (main.jsbundle:1066:119)
2 ??? 0x0 <unknown> + 1066 (main.jsbundle:1066:387)
3 ??? 0x0 <unknown> + 1028 (main.jsbundle:1028:8462)
4 ??? 0x0 u + 63 (main.jsbundle:63:157)
5 ??? 0x0 <unknown> + 63 (main.jsbundle:63:866)
6 ??? 0x0 k + 70 (main.jsbundle:70:513)
7 ??? 0x0 w + 70 (main.jsbundle:70:911)
8 ??? 0x0 callReactNativeMicrotasks + 70 (main.jsbundle:70:3067)
9 ??? 0x0 <unknown> + 33 (main.jsbundle:33:2872)
10 ??? 0x0 <unknown> + 33 (main.jsbundle:33:1108)
11 ??? 0x0 <unknown> + 33 (main.jsbundle:33:2532)
12 ??? 0x0 <unknown> + 33 (main.jsbundle:33:1067)
And the correct output:
Non-fatal Exception: JavaScriptError
0 ??? 0x0 <unknown> (apiWithRetrySaga exceeded retries)
1 ??? 0x0 t + 1066 (/Users/dave/Projects/cea-native/src/shared/components/HttpError.js:3:HttpError)
2 ??? 0x0 <unknown> + 1066 (/Users/dave/Projects/cea-native/src/shared/components/HttpError.js:24:createHttpErrorFromAPIResponse)
3 ??? 0x0 <unknown> + 1028 (/Users/dave/Projects/cea-native/src/sagas/api/http-json.js:99:axios.then$argument_1)
4 ??? 0x0 u + 63 (/Users/dave/Projects/cea-native/node_modules/promise/setimmediate/core.js:37:tryCallOne)
5 ??? 0x0 <unknown> + 63 (/Users/dave/Projects/cea-native/node_modules/promise/setimmediate/core.js:123:setImmediate$argument_0)
6 ??? 0x0 k + 70 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:112:_callTimer)
7 ??? 0x0 w + 70 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:166:_callReactNativeMicrotasksPass)
8 ??? 0x0 callReactNativeMicrotasks + 70 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/Core/Timers/JSTimers.js:418:callReactNativeMicrotasks)
9 ??? 0x0 <unknown> + 33 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:393:__callReactNativeMicrotasks)
10 ??? 0x0 <unknown> + 33 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:__guard$argument_0)
11 ??? 0x0 <unknown> + 33 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:370:__guard)
12 ??? 0x0 <unknown> + 33 (/Users/dave/Projects/cea-native/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:__guard$argument_0)
These correct results match the output from a similar stack trace I processed from Android.
My project is a bit behind versions, on 0.66.2 of metro-react-native-babel-preset
, so maybe this issue is due to changes that have occurred since that version. Or maybe something on Crashlytics is now producing output different from what this tool expects.
Thanks @daveham, I got this working on my end as well thanks to you. My metro-react-native-babel-preset
version is 0.77.3 and the behavior is the same.
Currently using metro-react-native-babel-preset
0.73.9
and getting this error. There are no instances of [native code]
or :0:0
in my stacktrace from Crashlytics.
Hey, I have a question ... why while running metro-symbolicate to the correct file I get nothing in return? Does anyone know?
Currently using
metro-react-native-babel-preset
0.73.9
and getting this error. There are no instances of[native code]
or:0:0
in my stacktrace from Crashlytics.
Thanks it is working.
I am also facing the same issue. My stacktrace does not have [native code]
or :0:0
.
I tried mocking a simple crash by below code.
mockCrashFn = () => {
throw new Error('This is a mock crash!');
}
Even symbolcating this crash's stacktrace is throwing the same error - TypeError: Line must be greater than or equal to 1, got 0
Note: I am using react-native 0.72.10 and hermes is disabled in my project.
Below is some of the lines of the stacktrace from crashlytics:
Fatal Exception: com.facebook.react.common.JavascriptException: Error: This is a mock crash!, stack:
<unknown>@3051:1757
<unknown>@3051:9467
<unknown>@97:1248
k@97:498
callTimers@97:2655
value@30:3860
<unknown>@30:675
value@30:2510
value@30:646
value@-1
at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:65)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
…
I tried removing all the lines after value@-1
in the stack trace and symbolification worked.