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

UnexpectedNativeTypeException: Value for message cannot be cast from ReadableNativeMap to String #652

Closed
4 of 7 tasks
matthias-pichler opened this issue Sep 5, 2019 · 5 comments

Comments

@matthias-pichler
Copy link

matthias-pichler commented Sep 5, 2019

OS:

  • Windows
  • MacOS
  • Linux

Platform:

  • iOS
  • Android

SDK:

  • @sentry/react-native
  • react-native-sentry

react-native version: 0.60.5

Init Code:

Sentry.init({
  dsn: Config.SENTRY_DSN,
  environment: process.env.NODE_ENV || 'development'
});

I have following issue:

As soon as I call init on the Sentry SDK my app crashes with UnexpectedNativeTypeException: Value for message cannot be cast from ReadableNativeMap to String. Though this only happens on Android and not on iOS.

This issue was reported in the beta as well: #612 (comment)

and #651 also seems related:

react-native info

info Fetching system and libraries information...
System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 105.25 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.9.1 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.10.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: ^16.9.0 => 16.9.0 
    react-native: ^0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

screenshot:
image

stacktrace in logcat:

09-05 13:56:09.528  7448  7530 E unknown:ReactNative: Exception in native call
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: com.facebook.react.bridge.UnexpectedNativeTypeException: Value for message cannot be cast from ReadableNativeMap to String
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.ReadableNativeMap.checkInstance(ReadableNativeMap.java:141)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.ReadableNativeMap.getNullableValue(ReadableNativeMap.java:129)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.ReadableNativeMap.getString(ReadableNativeMap.java:163)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at io.sentry.RNSentryModule.sendEvent(RNSentryModule.java:209)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at java.lang.reflect.Method.invoke(Native Method)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at android.os.Handler.handleCallback(Handler.java:873)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at android.os.Looper.loop(Looper.java:193)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
09-05 13:56:09.528  7448  7530 E unknown:ReactNative: 	at java.lang.Thread.run(Thread.java:764)

Steps to reproduce:

  • call init on react-native 0.60.5 with @sentry/react-native 1.0.4

Actual result:

  • App crashes with UnexpectedNativeTypeException

Expected result:

  • SDK is set up successfully
@HazAT
Copy link
Member

HazAT commented Sep 5, 2019

OK, I know how to fix this error but I want to understand how this happens.
So there is no other place in your codebase where you have any calls to Sentry.*?

The error message clearly says that the value of event.message is not a string.

Edit: logLevel is not longer support in the options, maybe this triggers an error.

@matthias-pichler
Copy link
Author

@HazAT
Ok thanks for the hint about logLevel.

I removed every call to Sentry in my Application and replaced the init call with just the dsn. Still the same error

@HazAT
Copy link
Member

HazAT commented Sep 5, 2019

I am really curious, the fix is easy, I need to safeguard it like here:

try {
if (breadcrumb.hasKey("data") && breadcrumb.getMap("data") != null) {
Map<String, String> newData = new HashMap<>();
for (Map.Entry<String, Object> data : ((ReadableNativeMap)breadcrumb.getMap("data")).toHashMap().entrySet()) {
newData.put(data.getKey(), data.getValue() != null ? data.getValue().toString() : null);
}
breadcrumbBuilder.setData(newData);
}
} catch (UnexpectedNativeTypeException e) {
logger.warning("Discarded breadcrumb.data since it was not an object");
} catch (ClassCastException e) { // This needs to be here for RN < 0.60
logger.warning("Discarded breadcrumb.data since it was not an object");
}

But is it possible for you to inspect the value of event.getMap('message')?
I want to know the value so I can understand where this is coming from. If it's from our SDK internally I need to fix this in another place.

@matthias-pichler
Copy link
Author

So it was in fact super interesting what caused this error but totally unrelated to anything discussed here:
See: #653

@mikeRChambers610
Copy link

what is the fix....?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants