Sentry-react-native: java.lang.Double cannot be cast to java.lang.String

Created on 3 Jul 2018  ·  6Comments  ·  Source: getsentry/sentry-react-native

OS:

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

_Platform:_

  • [ ] iOS
  • [x] Android

Output of node -v && npm -v && npm ls --prod --depth=0

v9.11.1
6.0.1
[email protected] /Users/simon/Documents/kimoby/kimobile
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] (git+https://[email protected]/eleretic/react-native-newrelic.git#a1b64afe379b8da6d8a23948288a13c061d5d404)
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Config:

Sentry.config('🔑').install()

I have following issue:

I try to set user context with

Sentry.setUserContext({ userId: 1293847 })

I got this error:

screen shot 2018-07-03 at 9 30 13 am

Stacktrace:

java.lang.Double cannot be cast to java.lang.String
getString
    ReadableNativeMap.java:168
getUserBuilder
    RNSentryModule.java:295
setUser
    RNSentryModule.java:177
invoke
    Method.java
invoke
    JavaMethodWrapper.java:372
invoke
    JavaModuleWrapper.java:160
run
    NativeRunnable.java
handleCallback
    Handler.java:739
dispatchMessage
    Handler.java:95
dispatchMessage
    MessageQueueThreadHandler.java:29
loop
    Looper.java:148
run
    MessageQueueThreadImpl.java:192
run
    Thread.java:818

I tried with

Sentry.setUserContext({ foo: 1293847 })

I had no error.

Most helpful comment

I ran into the same issue, I haven't seen any mention that userId must be a string in the documentation.

JavaScript is a dynamic language, you can't expect values coming from the JS side to strictly match a string or a double, you should convert between the two representations internally.

All 6 comments

Hi there, I just edited this for you. Try not to post your DSN on GitHub.

Please make the userId a string, this should fix it.

It doesn't look like the right way to do it, can't you detect the type instead of making the supposition that it's a _String_?

https://github.com/getsentry/react-native-sentry/blob/e04f429de7fbec10b3fc17a4d6a9ce094e1345e5/android/src/main/java/io/sentry/RNSentryModule.java#L297

@HazAT

I ran into the same issue, I haven't seen any mention that userId must be a string in the documentation.

JavaScript is a dynamic language, you can't expect values coming from the JS side to strictly match a string or a double, you should convert between the two representations internally.

@sryze Is absolutely right, this is extremely unexpected behavior. Thanks @HazAT and @masterT for providing a temporary solution and explanation of the underlying issue!

Just ran into this issue today - coincided with building for 64 bit systems as required by Android. Maybe a coincidence, or maybe a lot more people will be encountering this issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kriptonhaz picture kriptonhaz  ·  3Comments

brainbicycle picture brainbicycle  ·  3Comments

juhaelee picture juhaelee  ·  3Comments

sercanov picture sercanov  ·  3Comments

KevinColemanInc picture KevinColemanInc  ·  3Comments