Sentry-react-native: Unhandled Promise rejection causes UnexpectedNativeTypeException

Created on 5 Sep 2019  路  12Comments  路  Source: getsentry/sentry-react-native

OS:

  • [x] Windows
  • [x] MacOS
  • [ ] Linux

_Platform:_

  • [ ] iOS
  • [x] Android

SDK:

  • [ ] @sentry/react-native
  • [x] 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:

When a promise rejection is not handled the sentry sdk crashes with an UnexpectedNativeTypeException. But only if the promise rejects with an object that is not of type Error. So Promise.reject({bar: 'foo'}); will crash but Promise.reject(new Error('foo')); and Promise.reject('foo'); will not.

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:
-

Promise.reject({bar: 'foo'});

Actual result:

  • App crashes with UnexpectedNativeTypeException

Expected result:

  • Report promise rejection

Most helpful comment

Fixed this issue by changing

Sentry.captureMessage('My message', { level: Sentry.Severity.Debug, });

to

Sentry.captureMessage('My message', Sentry.Severity.Debug);

All 12 comments

Thanks for clarifying the other issue and thanks for the detailed and helpful bug report.
I will fix this and let you know when the new release is out.

With previous versions, it was possible to set handlePromiseRejection: false. Is there any way to work around this issue with v1 ?

@agarant
You should be able to do:

Sentry.init({
  ...
  integrations: [
    new Sentry.BrowserIntegrations.GlobalHandlers({
      onerror: true,
      onunhandledrejection: false
    })
  ]
});

Please test 1.0.5 the issue should be fixed there.

Hey guys,

I am getting the same in production on react-native 0.61.2 and sentry 1.0.7.

I am not able to reproduce on a device, but it seems to be Android only.

I can see a few of these events showing up in production.

com.facebook.react.bridge.UnexpectedNativeTypeException: Value for level cannot be cast from ReadableNativeMap to String
    at com.facebook.react.bridge.ReadableNativeMap.checkInstance(ReadableNativeMap.java:139)
    at com.facebook.react.bridge.ReadableNativeMap.getNullableValue(ReadableNativeMap.java:127)
    at com.facebook.react.bridge.ReadableNativeMap.getString(ReadableNativeMap.java:161)
    at io.sentry.RNSentryModule.eventLevel(RNSentryModule.java:436)
    at io.sentry.RNSentryModule.sendEvent(RNSentryModule.java:175)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
    at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
    at android.os.Looper.loop(Looper.java:193)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
    at java.lang.Thread.run(Thread.java:764)

The error is the following.

Value for level cannot be cast from ReadableNativeMap to String

EDIT: I have tried with the Promise, as mentioned above, and I can see an event being recorded on the sentry dashboard, but I didn't get any crash, just the following:

{ NativeMap: {"bar":"foo"} }

@HazAT any idea? 馃槄

I'm seeing the same error. react-native 0.60.6 and sentry 1.0.7.

I have got this straight after upgrading from react-native 0.59.5 to 0.61.2

same here with react version 0.61.2 adn sentry 1.0.9

Same here react native version 0.60.6 sentry 1.0.9

Also seeing it here RN 0.61.2 Sentry 1.0.9

Also happening for me on RN 0.60.5 Sentry 1.0.9

Error message Value for level cannot be cast from ReadableNativeMap to String

Fixed this issue by changing

Sentry.captureMessage('My message', { level: Sentry.Severity.Debug, });

to

Sentry.captureMessage('My message', Sentry.Severity.Debug);

Was this page helpful?
0 / 5 - 0 ratings