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

Invariant Violation when passing an object with Infinity into `addBreadcrumb`

Open thomasttvo opened this issue 1 year ago • 5 comments

OS:

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

Platform:

  • [ ] iOS
  • [x] Android

SDK:

  • [x] @sentry/react-native (>= 1.0.0)
  • [ ] react-native-sentry (<= 0.43.2)

SDK version: 5.29.0

react-native version: 0.73.5

Are you using Expo?

  • [ ] Yes
  • [x] No

Are you using sentry.io or on-premise?

  • [x] sentry.io (SaaS)
  • [ ] on-premise

Calling addBreadcrumb on Android with an Infinity value throws an error, which may crash the app in certain cases. We don't usually mean to call it with an Infinity value, but it's hard to control what's being logged automatically.

I think at the very least, Sentry should wrap its methods around try/catch internally and log the errors to avoid them affecting the main application?

try {
  Sentry.addBreadcrumb({
     category: 'redux.action',
     type: 'info',
     data: { x: Infinity },
  });
} catch(e) {
  console.log(e)
}
Invariant Violation: [{"timestamp":1723673438.573,"category":"redux.action","type":"info","data":{"x":"<<Infinity>>"},"level":"info"}] is not usable as a native method argument, js engine: hermes

thomasttvo avatar Aug 14 '24 22:08 thomasttvo

Hi @thomasttvo, thank you for the message,

we recommend adding know data structures to the breadcrumb, but regardless that, the addBreadcrumbs function should not throw.

krystofwoldrich avatar Aug 16 '24 11:08 krystofwoldrich

  • Normalization of infinity will be fixed in JS by https://github.com/getsentry/sentry-javascript/pull/13406

krystofwoldrich avatar Aug 16 '24 14:08 krystofwoldrich

After running the sample code I'm not getting the same error but malformed JS call.

It looks like RN serialization error.

krystofwoldrich avatar Aug 16 '24 14:08 krystofwoldrich

After running the sample code I'm not getting the same error but malformed JS call.

It looks like RN serialization error.

I believe the malformed JS is caused by RN catching the uncaught error and doing some processing with it. If you wrap it around a try/catch, you'll get the error I mentioned

thomasttvo avatar Aug 16 '24 16:08 thomasttvo

Thank you, I did that, but the malformed JS is a native error and is not captured by the JS try/catch.

krystofwoldrich avatar Aug 19 '24 08:08 krystofwoldrich

Fixed in https://github.com/getsentry/sentry-react-native/releases/tag/6.0.0 and newer.

krystofwoldrich avatar Dec 10 '24 12:12 krystofwoldrich