sentry-dart icon indicating copy to clipboard operation
sentry-dart copied to clipboard

`setExtra` while configuring scope throw ClassCastException

Open clementperineau opened this issue 1 year ago • 2 comments

Platform

Dart

Obfuscation

Disabled

Debug Info

Disabled

Doctor

Dart 3.3.3

Version

8.2.0

Steps to Reproduce

Use setExtra while configuring scope

Sentry.configureScope(
  (scope) {
    scope.setExtra('extra_data', 'data');
  },
);

Expected Result

Add extra data to scope.

Actual Result

Throw platform error when calling native code using platform channel.

I guess setExtra should be deprecated. But the method does not have deprecated flag.

PlatformException (PlatformException(error, java.lang.Integer cannot be cast to java.lang.String, null, java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at io.sentry.flutter.SentryFlutterPlugin.onMethodCall(SentryFlutterPlugin.kt:70)
	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7898)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
))

Are you willing to submit a PR?

None

clementperineau avatar Jun 12 '24 15:06 clementperineau

Hi thx for the issue

it seems to be an oversight since the setExtra function in Scope should've been deprecated in v8

buenaflor avatar Jun 14 '24 11:06 buenaflor

In general we recommend using contexts instead of extra, see here

buenaflor avatar Jun 18 '24 09:06 buenaflor