react-native-fabric icon indicating copy to clipboard operation
react-native-fabric copied to clipboard

Can't record an error with Crashlytics.recordError()

Open igorarkhipenko opened this issue 8 years ago • 8 comments
trafficstars

So that pretty much it is. Crashlytics.crash() does well and everything gets recorded as expected, but not in case with recordError(error) method. My code snipped is below and it's needless to say that componentDidCatch() method is called as well.

componentDidCatch(error, info) {
    Crashlytics.recordError(error);
  }

What could be the reason of such behavior? Any help is appreciated.

igorarkhipenko avatar Nov 08 '17 12:11 igorarkhipenko

recordError only works on iOS and the reverse is true of logException on Android. Are you on Android? I've added code in my exception handles to check Platform.OS before calling a method but its less than ideal.

willderness avatar Nov 13 '17 20:11 willderness

@willderness no, I use iOS device and emulator for testing and still can't make it work. How is that even possible? The very first and basic function doesn't work for some reason. Thanks for your reply.

igorarkhipenko avatar Nov 13 '17 20:11 igorarkhipenko

@igorarkhipenko after having the same issue myself i realized recordError only works on an actual device and does not work via the emulator. Hope this helps

shyaniv7 avatar Jan 08 '18 22:01 shyaniv7

I created a helper for logging errors feel free to use it

import { Crashlytics } from "react-native-fabric";
import { Platform } from "react-native";

export default logError = ( err ) => {
  if ( Platform.OS === "ios" ) {
    Crashlytics.recordError( err );
  } else {
    Crashlytics.logException( err );
  }
  console.log( err );
};

console.log should help you in the emulator

shyaniv7 avatar Jan 08 '18 22:01 shyaniv7

@shyaniv7 could you please elaborate on what environments you manage to makes it work?

alvinmatias69 avatar Jul 01 '18 04:07 alvinmatias69

As stated in the code this will log an error to crashlytics on both android and iOS using a single logError function.

shyaniv7 avatar Jul 01 '18 15:07 shyaniv7

@shyaniv7 I mean configuration like are you on debug mode, simulator, or device. Something like that

alvinmatias69 avatar Jul 01 '18 16:07 alvinmatias69

We actually have environment variables where we are able to know what environment we are running, what device, api version, app version and more information and whenever we use the logError we concatenate those information onto the error message before logging it.

We wrote a fetch wrapper that makes our api requests and handles any caught errors using logError

shyaniv7 avatar Jul 01 '18 16:07 shyaniv7