getsentry / sentry-dart

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

PlatformException on Android isn't correctly parsed #2041

Closed ueman closed 5 months ago

ueman commented 6 months ago

I can't reopen #2001, so here's a new issue since #2001 isn't actually fixed in #2033.

The issue is that the exception seen below has the stacktrace in the details field, but the details field is not parse. In practice, I never see the stacktrace in the message field, however the message field is correctly parsed if present.

It's probably a good idea to let details take precedence over message.

Platform

Flutter Mobile

Obfuscation

Disabled

Debug Info

Disabled

Doctor

flutter doctor -v
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.3.1 23D60 darwin-arm64, locale en-DE)
    • Flutter version 3.19.3 on channel stable at /Users/ueman/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (5 weeks ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/ueman/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.88.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.86.0

[✓] Connected device (4 available)
    • iPhone-GWTGT1UTPLJQ (mobile) • 00008030-000E4D310CD3402E            • ios            • iOS 17.4.1 21E236
    • iPhone 15 Pro Max (mobile)   • 4E4B3D83-EAA8-490B-B699-90A09831AC06 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator)
    • macOS (desktop)              • macos                                • darwin-arm64   • macOS 14.3.1 23D60 darwin-arm64
    • Chrome (web)                 • chrome                               • web-javascript • Google Chrome 123.0.6312.107

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Version

7.18.0

Steps to Reproduce

Catch the PlatformException mentioned below

Expected Result

The exception is correctly parsed.

Actual Result

PlatformException: PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f14000d
    at android.content.res.ResourcesImpl.getResourceEntryName(ResourcesImpl.java:493)
    at android.content.res.Resources.getResourceEntryName(Resources.java:2441)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getMappedNotificationChannel(FlutterLocalNotificationsPlugin.java:170)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getNotificationChannels(FlutterLocalNotificationsPlugin.java:32)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:399)
    at be.j$a.a(MethodChannel.java:18)
    at pd.c.l(DartMessenger.java:19)
    at pd.c.m(DartMessenger.java:42)
    at pd.c.h(Unknown Source:0)
    at pd.b.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:966)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:293)
    at android.app.ActivityThread.loopProcess(ActivityThread.java:9832)
    at android.app.ActivityThread.main(ActivityThread.java:9821)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1201)
, null)

which corresponds to the following Dart code:

final e = PlatformException(
  code: 'getNotificationChannelsError',
  message: 'Unable to find resource ID #0x7f14000d',
  details: '''android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d
    at android.content.res.ResourcesImpl.getResourceEntryName(ResourcesImpl.java:493)
    at android.content.res.Resources.getResourceEntryName(Resources.java:2441)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getMappedNotificationChannel(FlutterLocalNotificationsPlugin.java:170)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getNotificationChannels(FlutterLocalNotificationsPlugin.java:32)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:399)
    at be.j\$a.a(MethodChannel.java:18)
    at pd.c.l(DartMessenger.java:19)
    at pd.c.m(DartMessenger.java:42)
    at pd.c.h(Unknown Source:0)
    at pd.b.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:966)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:293)
    at android.app.ActivityThread.loopProcess(ActivityThread.java:9832)
    at android.app.ActivityThread.main(ActivityThread.java:9821)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:586)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1201)''',
  stacktrace: null,
);

Screenshot 2024-04-21 at 21 42 53

Are you willing to submit a PR?

None

ueman commented 6 months ago

Re: https://github.com/getsentry/sentry-dart/pull/2033#issuecomment-2107057981

@ueman Just for clarification, I based the exception on the tests that were there:

https://github.com/getsentry/sentry-dart/blob/0f067d38500c0ab6b9e85d0b19690ba915d4fea1/flutter/test/android_platform_exception_event_processor_test.dart#L196

Is this then also incorrect, as it also puts the stacktrace string into message and stacktrace properties? The order of message/details is also different in the ctor than in the test sample declarations.

I think I messed up when implementing that, since I've never seen a stacktrace in the message property, but I've seen plenty stacktraces in the details property

denrase commented 6 months ago

Any easy way to provoke a PlatformException to have one more example?

ueman commented 6 months ago

I can take a look at what we observe in production and add some more examples