Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find error code line in crashlytics #1783

Closed
nguyenhoanglam opened this issue Dec 22, 2018 · 21 comments
Closed

Find error code line in crashlytics #1783

nguyenhoanglam opened this issue Dec 22, 2018 · 21 comments
Assignees
Labels
plugin: crashlytics Firebase Crashlytics Type: Stale Issue has become stale - automatically added by Stale bot
Milestone

Comments

@nguyenhoanglam
Copy link

nguyenhoanglam commented Dec 22, 2018

I've tested the crashlytics by adding an error Javascript's code. The iOS crash was reported in Firebase console like below:

Crashed: com.squareup.SocketRocket.NetworkThread
0  libobjc.A.dylib                0x10d65bd8b objc_msgSend + 11
1  CoreFoundation                 0x10eee5754 _signalEventSync + 228
2  CoreFoundation                 0x10eee4d36 _cfstream_shared_signalEventSync + 470
3  CoreFoundation                 0x10eece721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
4  CoreFoundation                 0x10eecdf93 __CFRunLoopDoSources0 + 243
5  CoreFoundation                 0x10eec863f __CFRunLoopRun + 1263
6  CoreFoundation                 0x10eec7e11 CFRunLoopRunSpecific + 625
7  Foundation                     0x10c9e3322 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 277
8  Lotte                          0x10bb90431 -[_RCTSRRunLoopThread main] (RCTSRWebSocket.m:1592)
9  Foundation                     0x10c9f8732 __NSThread__start__ + 1221
10 libsystem_pthread.dylib        0x111235339 _pthread_body + 126
11 libsystem_pthread.dylib        0x1112382a7 _pthread_start + 70
12 libsystem_pthread.dylib        0x111234445 thread_start + 13

How can I detect which file (or Javascript's code line) that cause the crash?

@StefanoCremona
Copy link

StefanoCremona commented Jan 16, 2019

No way so far for me to upload the source maps and see the line of code.
Firebase reports just the native error.

On the other hand, following this thread
#1052
I was able to intercept the RN errors and log remotely the stack:

in the app.js:

//Define an error handler to upload thet stack to crashlytics
const defaultHandler = global.ErrorUtils.getGlobalHandler()
const crashlytics = firebase.crashlytics()

global.ErrorUtils.setGlobalHandler((...args) => {
  const error = args[0] || 'Unknown'
  //console.log('Crashlytics error sent', error);

  if (error instanceof Error) {
    crashlytics.setStringValue('stack', `${error.stack}`)
    crashlytics.setStringValue('message', `${error.message}`)
    crashlytics.recordError(0, `RN Fatal: ${error.message}`)
  } else {
    // Have never gotten this log so far. Might not be necessary.
    crashlytics.recordError(0, `RN Fatal: ${error}`)
  }
  crashlytics.log(error.message);

  defaultHandler.apply(this, args);
  //force the native crash
  crashlytics.crash();
});

So on my Crashlytics console I can see something like:

-[RNFirebaseCrashlytics log:] line 26 $ TypeError: undefined is not an object (evaluating '_styles.default.fakeOne.fakeProp')

This error is located at:
   in About (created by Connect(About))
   in Connect(About) (at screenWrapper.js:52)
   in RCTView (at View.js:45)
   in ErrorMessageProvider (at screenWrapper.js:69)
   in Provider (at screenWrapper.js:68)
   in ScreenWrapper (at Navigation.js:51)
   in _class (at renderApplication.js:34)
   in RCTView (at View.js:45)
   in RCTView (at View.js:45)
   in AppContainer (at renderApplication.js:33)

Consider to move to Sentry, that allows you to upload the source maps and shows you the actual javascript line of code that generated the error.

@isurugajasinghe
Copy link

can you pls explain where i need to place below code.

const defaultHandler = global.ErrorUtils.getGlobalHandler()
const crashlytics = firebase.crashlytics()

global.ErrorUtils.setGlobalHandler((...args) => {
const error = args[0] || 'Unknown'
//console.log('Crashlytics error sent', error);

if (error instanceof Error) {
crashlytics.setStringValue('stack', ${error.stack})
crashlytics.setStringValue('message', ${error.message})
crashlytics.recordError(0, RN Fatal: ${error.message})
} else {
// Have never gotten this log so far. Might not be necessary.
crashlytics.recordError(0, RN Fatal: ${error})
}
crashlytics.log(error.message);

defaultHandler.apply(this, args);
//force the native crash
crashlytics.crash();
});

my index.js is

console.disableYellowBox = true;

import { Navigation } from "react-native-navigation";
import { registerScreens } from "./src/config/routes";
import { addListeners } from "./src/utilities/listeners";
import { Provider } from "react-redux";
import setup from "./src/store/setup";
import { iconsMap, iconsLoaded } from "./src/utilities/AppIcons";

Navigation.events().registerAppLaunchedListener(() => {
const store = setup();
registerScreens(store, Provider);
addListeners();
});

@StefanoCremona
Copy link

You can add it after your last 'import' statement.
Remember to import firebase as well.

I also found this tutorial to upload all the RN logs.
https://medium.com/delivery-com-engineering/add-crashlytics-to-your-react-native-ios-app-69a983a9062a

@isurugajasinghe
Copy link

@StefanoCremona
Hi this is my index.js


import { Navigation } from "react-native-navigation";
import { registerScreens } from "./src/config/routes";
import { addListeners } from "./src/utilities/listeners";
import { Provider } from "react-redux";
import setup from "./src/store/setup";
import { iconsMap, iconsLoaded } from "./src/utilities/AppIcons";

Navigation.events().registerAppLaunchedListener(() => {
const store = setup();
registerScreens(store, Provider);
addListeners();
});```

can you please tell me where need to modify ?

@StefanoCremona
Copy link

Your file could be like this:

import { Navigation } from "react-native-navigation";
import { registerScreens } from "./src/config/routes";
import { addListeners } from "./src/utilities/listeners";
import { Provider } from "react-redux";
import setup from "./src/store/setup";
import { iconsMap, iconsLoaded } from "./src/utilities/AppIcons";

//****************   Update starts here   ****************
import firebase from 'react-native-firebase';

//Define an error handler to upload thet stack to crashlytics
const defaultHandler = global.ErrorUtils.getGlobalHandler()
const crashlytics = firebase.crashlytics()

global.ErrorUtils.setGlobalHandler((...args) => {
  const error = args[0] || 'Unknown'
  //console.log('Crashlytics error sent', error);

  if (error instanceof Error) {
    crashlytics.setStringValue('stack', `${error.stack}`)
    crashlytics.setStringValue('message', `${error.message}`)
    crashlytics.recordError(0, `RN Fatal: ${error.message}`)
  } else {
    // Have never gotten this log so far. Might not be necessary.
    crashlytics.recordError(0, `RN Fatal: ${error}`)
  }
  crashlytics.log(error.message);

  defaultHandler.apply(this, args);
  //force the native crash
  crashlytics.crash();
});
//****************   Update ends here   ****************

Navigation.events().registerAppLaunchedListener(() => {
const store = setup();
registerScreens(store, Provider);
addListeners();
});

@isurugajasinghe
Copy link

Thank you
But I added debug point inside the global.ErrorUtils.setGlobalHandler((...args) => {
debug point not working. how can I know whether this method working or not ?

@cylim
Copy link

cylim commented Jan 21, 2019

I believe you can use crashlytics.crash(); anywhere in your app to see whether it show proper log in your crashlytics portal.

@Salakar
Copy link
Member

Salakar commented Jan 21, 2019

FYI; upcoming v6.0.0 will capture JavaScript stack traces by default.

@Salakar Salakar added this to the v6.0.0 milestone Jan 21, 2019
@StefanoCremona
Copy link

Thank you
But I added debug point inside the global.ErrorUtils.setGlobalHandler((...args) => {
debug point not working. how can I know whether this method working or not ?

You have to trigger a React Native error, like for example, as you press a button:

console.log('Force an error: ', this.fakeObj.fakeProp);

@stale
Copy link

stale bot commented Feb 18, 2019

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Feb 18, 2019
@Salakar Salakar mentioned this issue Mar 11, 2019
22 tasks
Salakar added a commit that referenced this issue Mar 13, 2019
[crashlytics]

Fixes: #1643, #1848, #1964, #1920, #1884, #1783, #1966, #1940, #1447

Features/Bugs Todo:

  Capture JS Exceptions with stack traces automatically
  Capture Unhandled Promise Rejections with stack traces automatically
  [Android] .crash() not captured in debug due to RN RedBox; see #1921
  Support advanced user identifier features
  [Android] Enable Crashlyics NDK reporting by default (gist)
  Support toggling native crash logging off/on (e.g. disable in DEV)
  Support toggling JS crash logging off/on (e.g. disable in DEV)

  [ios] Static framework support for all modules
  [ios] Implement CocoaPods Firebase RN modules auto-loader script
  Implement firebase.json config loader; Android & iOS
  [tests] Fix false positive tests that catch errors (tests did not check that errors actually threw)
  [android] Cleanup manifest permissions for all modules
  [android] Implement Content provider base class
  [android] Investigate/fix issue where setDataCollectionDefaultEnabled is false by default in Firebase - it disables Crashlytics reporting
@Salakar
Copy link
Member

Salakar commented Mar 13, 2019

Hey all, Crashlytics has recently had a major overhaul in #1958 - this will land as part of v6.

As this issue no longer applies (JS stack traces/Errors instances now captured by default, incl. unhandled promise rejections) I will close and lock this issue.

[The full changelog can be viewed here]

If you have any feedback/queries relating to the PR above please ask in the #crashlytics discord channel or create an issue with [v6] in the title.

Thanks for reporting and thanks for your patience 💛


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

@Salakar Salakar closed this as completed Mar 13, 2019
@Salakar Salakar added the plugin: crashlytics Firebase Crashlytics label Mar 13, 2019
@Salakar Salakar self-assigned this Mar 13, 2019
7patricia pushed a commit to uphold-forks/react-native-firebase that referenced this issue Nov 29, 2019
…rtase#1958)

[crashlytics]

Fixes: invertase#1643, invertase#1848, invertase#1964, invertase#1920, invertase#1884, invertase#1783, invertase#1966, invertase#1940, invertase#1447

Features/Bugs Todo:

  Capture JS Exceptions with stack traces automatically
  Capture Unhandled Promise Rejections with stack traces automatically
  [Android] .crash() not captured in debug due to RN RedBox; see invertase#1921
  Support advanced user identifier features
  [Android] Enable Crashlyics NDK reporting by default (gist)
  Support toggling native crash logging off/on (e.g. disable in DEV)
  Support toggling JS crash logging off/on (e.g. disable in DEV)

  [ios] Static framework support for all modules
  [ios] Implement CocoaPods Firebase RN modules auto-loader script
  Implement firebase.json config loader; Android & iOS
  [tests] Fix false positive tests that catch errors (tests did not check that errors actually threw)
  [android] Cleanup manifest permissions for all modules
  [android] Implement Content provider base class
  [android] Investigate/fix issue where setDataCollectionDefaultEnabled is false by default in Firebase - it disables Crashlytics reporting
@kbanashek
Copy link

I'm still not seeing javascript stack traces being logged by default after implementing v6.2 running on iOS simulator & RN 61.5

@hxiongtw
Copy link

hxiongtw commented Apr 2, 2020

Also not working for me...
"@react-native-firebase/app": "^6.3.4",
"@react-native-firebase/crashlytics": "^6.3.4",
"react-native": "^0.61.5",

Tagging @Salakar for comments. Considering there are 7 thumbs up, which I assume are 7 people including me not being able to get javascript stack trace logged by default.

Also, from https://invertase.io/blog/firebase-crashlytics-for-react-native?utm_source=github&utm_medium=changelog, there is this statementOptionally toggle automatic reporting of JavaScript unhandled Promise rejections to have them visible on the Firebase Crashlytics console.
Can't find how to toggle this. Where is it documented?

Is there anyone that actually is able to get this working?

@debadaracco
Copy link

Also not working for me...
"@react-native-firebase/app": "^6.3.4",
"@react-native-firebase/crashlytics": "^6.3.4",
"react-native": "^0.61.5",

Tagging @Salakar for comments. Considering there are 7 thumbs up, which I assume are 7 people including me not being able to get javascript stack trace logged by default.

Also, from https://invertase.io/blog/firebase-crashlytics-for-react-native?utm_source=github&utm_medium=changelog, there is this statementOptionally toggle automatic reporting of JavaScript unhandled Promise rejections to have them visible on the Firebase Crashlytics console.
Can't find how to toggle this. Where is it documented?

Is there anyone that actually is able to get this working?

I have the same problem!!!!

@StarryFire
Copy link

Yes, i have the exact same problem. My app crashed on a error thrown from a reducer in Redux and yet there is no JS stack trace showing.

@wddwycc
Copy link

wddwycc commented May 19, 2020

Same here, no JS stack trace, I'm using

 "@react-native-firebase/app": "6.4.0",
 "@react-native-firebase/crashlytics": "6.4.0",

@patelnets
Copy link

patelnets commented Aug 18, 2020

Same here i'm not seeing any JS stack trace.
"@react-native-firebase/app": "^8.3.1", "@react-native-firebase/crashlytics": "^8.3.1",

@nokite
Copy link

nokite commented Sep 27, 2020

Edit: opened a separate issue.
#4313

@mikehardy
Copy link
Collaborator

@nokite actual open source developers have the decency not to spam issues with complaints. You posted about the indecency of the error reports twice but I don't recall you proposing a decent PR?

@nokite
Copy link

nokite commented Sep 27, 2020

@nokite actual open source developers have the decency not to spam issues with complaints. You posted about the indecency of the error reports twice but I don't recall you proposing a decent PR?

Sorry if I came across this way, I really didn't mean it in a negative way! I appreciate all the effort put into this.

andersondanilo pushed a commit to vixtech/react-native-firebase that referenced this issue Nov 9, 2020
…rtase#1958)

[crashlytics]

Fixes: invertase#1643, invertase#1848, invertase#1964, invertase#1920, invertase#1884, invertase#1783, invertase#1966, invertase#1940, invertase#1447

Features/Bugs Todo:

  Capture JS Exceptions with stack traces automatically
  Capture Unhandled Promise Rejections with stack traces automatically
  [Android] .crash() not captured in debug due to RN RedBox; see invertase#1921
  Support advanced user identifier features
  [Android] Enable Crashlyics NDK reporting by default (gist)
  Support toggling native crash logging off/on (e.g. disable in DEV)
  Support toggling JS crash logging off/on (e.g. disable in DEV)

  [ios] Static framework support for all modules
  [ios] Implement CocoaPods Firebase RN modules auto-loader script
  Implement firebase.json config loader; Android & iOS
  [tests] Fix false positive tests that catch errors (tests did not check that errors actually threw)
  [android] Cleanup manifest permissions for all modules
  [android] Implement Content provider base class
  [android] Investigate/fix issue where setDataCollectionDefaultEnabled is false by default in Firebase - it disables Crashlytics reporting
@mohamedanwer123
Copy link

i can't see js line error

RN : 63.4
"@react-native-firebase/app": "^10.8.1",
"@react-native-firebase/crashlytics": "^10.8.1",

androidIsForVivek pushed a commit to androidIsForVivek/react-native-firebase that referenced this issue Aug 9, 2021
…rtase#1958)

[crashlytics]

Fixes: invertase#1643, invertase#1848, invertase#1964, invertase#1920, invertase#1884, invertase#1783, invertase#1966, invertase#1940, invertase#1447

Features/Bugs Todo:

  Capture JS Exceptions with stack traces automatically
  Capture Unhandled Promise Rejections with stack traces automatically
  [Android] .crash() not captured in debug due to RN RedBox; see invertase#1921
  Support advanced user identifier features
  [Android] Enable Crashlyics NDK reporting by default (gist)
  Support toggling native crash logging off/on (e.g. disable in DEV)
  Support toggling JS crash logging off/on (e.g. disable in DEV)

  [ios] Static framework support for all modules
  [ios] Implement CocoaPods Firebase RN modules auto-loader script
  Implement firebase.json config loader; Android & iOS
  [tests] Fix false positive tests that catch errors (tests did not check that errors actually threw)
  [android] Cleanup manifest permissions for all modules
  [android] Implement Content provider base class
  [android] Investigate/fix issue where setDataCollectionDefaultEnabled is false by default in Firebase - it disables Crashlytics reporting
androidIsForVivek pushed a commit to androidIsForVivek/react-native-firebase that referenced this issue Sep 15, 2021
…rtase#1958)

[crashlytics]

Fixes: invertase#1643, invertase#1848, invertase#1964, invertase#1920, invertase#1884, invertase#1783, invertase#1966, invertase#1940, invertase#1447

Features/Bugs Todo:

  Capture JS Exceptions with stack traces automatically
  Capture Unhandled Promise Rejections with stack traces automatically
  [Android] .crash() not captured in debug due to RN RedBox; see invertase#1921
  Support advanced user identifier features
  [Android] Enable Crashlyics NDK reporting by default (gist)
  Support toggling native crash logging off/on (e.g. disable in DEV)
  Support toggling JS crash logging off/on (e.g. disable in DEV)

  [ios] Static framework support for all modules
  [ios] Implement CocoaPods Firebase RN modules auto-loader script
  Implement firebase.json config loader; Android & iOS
  [tests] Fix false positive tests that catch errors (tests did not check that errors actually threw)
  [android] Cleanup manifest permissions for all modules
  [android] Implement Content provider base class
  [android] Investigate/fix issue where setDataCollectionDefaultEnabled is false by default in Firebase - it disables Crashlytics reporting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: crashlytics Firebase Crashlytics Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests