Skip to content

Commit 9fe67d5

Browse files
authored
Fix PlatformException title parsing (#2033)
1 parent a5031f1 commit 9fe67d5

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Adds app start spans to first transaction ([#2009](https://github.com/getsentry/sentry-dart/pull/2009))
88

9+
### Fixes
10+
11+
- Fix `PlatformException` title parsing ([#2033](https://github.com/getsentry/sentry-dart/pull/2033))
12+
913
## 8.1.0
1014

1115
### Features

flutter/lib/src/event_processor/android_platform_exception_event_processor.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,14 @@ extension on JvmException {
153153
String? module;
154154
final typeParts = type?.split('.');
155155
if (typeParts != null) {
156-
if (typeParts.length > 1) {
156+
if (typeParts.isNotEmpty) {
157157
exceptionType = typeParts.last;
158158
}
159159
typeParts.remove(typeParts.last);
160-
module = typeParts.join('.');
160+
161+
if (typeParts.isNotEmpty) {
162+
module = typeParts.join('.');
163+
}
161164
}
162165
final stackFrames = stackTrace.asMap().entries.map((entry) {
163166
return entry.value.toSentryStackFrame(entry.key, nativePackageName);

flutter/test/android_platform_exception_event_processor_test.dart

+67
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,32 @@ void main() {
5151
expect(platformException_2.stackTrace!.frames.length, 18);
5252
});
5353

54+
test('platform exception is correctly parsed', () async {
55+
final platformExceptionEvent = await fixture.processor
56+
.apply(fixture.eventWithFailingPlatformStackTrace, Hint());
57+
58+
final exceptions = platformExceptionEvent!.exceptions!;
59+
expect(exceptions.length, 3);
60+
61+
final platformException = exceptions[1];
62+
63+
expect(platformException.type, 'PlatformException');
64+
expect(
65+
platformException.value,
66+
"PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d",
67+
);
68+
expect(platformException.stackTrace!.frames.length, 20);
69+
70+
final platformException_2 = exceptions[2];
71+
72+
expect(platformException_2.type, 'PlatformException');
73+
expect(
74+
platformException_2.value,
75+
"PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d",
76+
);
77+
expect(platformException_2.stackTrace!.frames.length, 20);
78+
});
79+
5480
test(
5581
'Dart thread is current and not crashed if Android exception is present',
5682
() async {
@@ -142,6 +168,16 @@ class Fixture {
142168
threads: [dartThread],
143169
);
144170

171+
late SentryException withFailingPlatformStackTrace = options.exceptionFactory
172+
.getSentryException(failingPlatformException)
173+
.copyWith(threadId: 1);
174+
175+
late SentryEvent eventWithFailingPlatformStackTrace = SentryEvent(
176+
exceptions: [withFailingPlatformStackTrace],
177+
throwable: failingPlatformException,
178+
threads: [dartThread],
179+
);
180+
145181
late SentryThread dartThread = SentryThread(
146182
crashed: true,
147183
current: true,
@@ -169,6 +205,14 @@ final emptyPlatformException = PlatformException(
169205
stacktrace: null,
170206
);
171207

208+
final failingPlatformException = PlatformException(
209+
code: 'error',
210+
details:
211+
"PlatformException: PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d",
212+
message: _failingStackTrace,
213+
stacktrace: _failingStackTrace,
214+
);
215+
172216
const _jvmStackTrace =
173217
"""java.lang.IllegalArgumentException: Unsupported value: '[Ljava.lang.StackTraceElement;@ba6feed' of type 'class [Ljava.lang.StackTraceElement;'
174218
at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:292)
@@ -189,3 +233,26 @@ const _jvmStackTrace =
189233
at java.lang.reflect.Method.invoke(Native Method)
190234
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:556)
191235
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)""";
236+
237+
const _failingStackTrace =
238+
"""PlatformException: PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d
239+
at android.content.res.ResourcesImpl.getResourceEntryName(ResourcesImpl.java:493)
240+
at android.content.res.Resources.getResourceEntryName(Resources.java:2441)
241+
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getMappedNotificationChannel(FlutterLocalNotificationsPlugin.java:170)
242+
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getNotificationChannels(FlutterLocalNotificationsPlugin.java:32)
243+
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:399)
244+
at be.j\$a.a(MethodChannel.java:18)
245+
at pd.c.l(DartMessenger.java:19)
246+
at pd.c.m(DartMessenger.java:42)
247+
at pd.c.h(Unknown Source:0)
248+
at pd.b.run(Unknown Source:12)
249+
at android.os.Handler.handleCallback(Handler.java:966)
250+
at android.os.Handler.dispatchMessage(Handler.java:110)
251+
at android.os.Looper.loopOnce(Looper.java:205)
252+
at android.os.Looper.loop(Looper.java:293)
253+
at android.app.ActivityThread.loopProcess(ActivityThread.java:9832)
254+
at android.app.ActivityThread.main(ActivityThread.java:9821)
255+
at java.lang.reflect.Method.invoke(Native Method)
256+
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:586)
257+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1201)
258+
, null)""";

0 commit comments

Comments
 (0)