getsentry / sentry-dart

Sentry SDK for Dart and Flutter
https://sentry.io/for/flutter/
MIT License
725 stars 223 forks source link

`setExtra` while configuring scope throw ClassCastException #2098

Open clementperineau opened 2 weeks ago

clementperineau commented 2 weeks ago

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

buenaflor commented 1 week ago

Hi thx for the issue

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

buenaflor commented 1 week ago

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