Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing stacktraces via MethodChannels from Android to Dart is broken #2088

Open
ueman opened this issue Sep 8, 2023 · 1 comment
Open

Comments

@ueman
Copy link
Contributor

ueman commented Sep 8, 2023

Describe the bug

We see the following issue in production:
Screenshot 2023-09-08 at 08 59 09

To Reproduce
Unfortunately, I don't know how to reproduce this issue.

Expected behavior
The actual real stacktrace should be shown

Sample code to reproduce the problem
Again, unfortunately, I don't know how to solve this problem.

Fix

Fortunately, I know how to fix the issue with the wrongly supported stacktraces.

The following code

https://github.com/MaikuB/flutter_local_notifications/blob/4d8aa14bb6ee12a8c3fa5a29d1eb82a5d57a8fe7/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L2002C1-L2016C4

should be changed to

  private void getNotificationChannels(Result result) {
    try {
      NotificationManagerCompat notificationManagerCompat =
          getNotificationManager(applicationContext);
      List<NotificationChannel> channels = notificationManagerCompat.getNotificationChannels();
      List<Map<String, Object>> channelsPayload = new ArrayList<>();
      for (NotificationChannel channel : channels) {
        HashMap<String, Object> channelPayload = getMappedNotificationChannel(channel);
        channelsPayload.add(channelPayload);
      }
      result.success(channelsPayload);
    } catch (Throwable e) {
      throw RuntimeException(throwable);
    }
  }

This is documented at https://api.flutter.dev/flutter/services/PlatformException/stacktrace.html

Unfortunately, we lose the GET_NOTIFICATION_CHANNELS_ERROR_CODE for the exception, but due to the issue seen in the screenshot above, it's anyway never used.

I haven't check whether there are any other occurences in the code base. Anyway, passing stacktraces to method channels is not safe, as they can't be serialized.

@Levi-Lesches
Copy link
Contributor

@ueman Fixed by #2103 or are you waiting to use Pigeon/RuntimeException?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants