-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
android_platform_exception_event_processor_test.dart
258 lines (211 loc) · 10.4 KB
/
android_platform_exception_event_processor_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@TestOn('vm')
// ignore_for_file: invalid_use_of_internal_member
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/event_processor/android_platform_exception_event_processor.dart';
import 'mocks.dart';
void main() {
late Fixture fixture;
setUp(() {
fixture = Fixture();
PackageInfo.setMockInitialValues(
appName: 'Sentry',
buildNumber: '1',
buildSignature: '',
packageName: 'io.sentry.samples',
version: '1.2.3',
installerStore: null,
);
});
group(AndroidPlatformExceptionEventProcessor, () {
test('exception is correctly parsed', () async {
final platformExceptionEvent = await fixture.processor
.apply(fixture.eventWithPlatformStackTrace, Hint());
final exceptions = platformExceptionEvent!.exceptions!;
expect(exceptions.length, 3);
final platformException = exceptions[1];
expect(platformException.type, 'IllegalArgumentException');
expect(
platformException.value,
"Unsupported value: '[Ljava.lang.StackTraceElement;@ba6feed' of type 'class [Ljava.lang.StackTraceElement;'",
);
expect(platformException.stackTrace!.frames.length, 18);
final platformException_2 = exceptions[2];
expect(platformException_2.type, 'IllegalArgumentException');
expect(
platformException_2.value,
"Unsupported value: '[Ljava.lang.StackTraceElement;@ba6feed' of type 'class [Ljava.lang.StackTraceElement;'",
);
expect(platformException_2.stackTrace!.frames.length, 18);
});
test('platform exception is correctly parsed', () async {
final platformExceptionEvent = await fixture.processor
.apply(fixture.eventWithFailingPlatformStackTrace, Hint());
final exceptions = platformExceptionEvent!.exceptions!;
expect(exceptions.length, 3);
final platformException = exceptions[1];
expect(platformException.type, 'PlatformException');
expect(
platformException.value,
"PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d",
);
expect(platformException.stackTrace!.frames.length, 20);
final platformException_2 = exceptions[2];
expect(platformException_2.type, 'PlatformException');
expect(
platformException_2.value,
"PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d",
);
expect(platformException_2.stackTrace!.frames.length, 20);
});
test(
'Dart thread is current and not crashed if Android exception is present',
() async {
final platformExceptionEvent = await fixture.processor
.apply(fixture.eventWithPlatformStackTrace, Hint());
final exceptions = platformExceptionEvent!.exceptions!;
expect(exceptions.length, 3);
expect(platformExceptionEvent.threads?.first.current, true);
expect(platformExceptionEvent.threads?.first.crashed, false);
});
test('platformexception has Android thread attached', () async {
final platformExceptionEvent = await fixture.processor
.apply(fixture.eventWithPlatformStackTrace, Hint());
final exceptions = platformExceptionEvent!.exceptions!;
expect(exceptions.length, 3);
final platformException = exceptions[1];
final platformThread = platformExceptionEvent.threads?[1];
expect(platformException.threadId, platformThread?.id);
expect(platformThread?.current, false);
expect(platformThread?.crashed, true);
expect(platformThread?.name, 'Android');
});
test('platformexception has no Android thread attached if disabled',
() async {
fixture.options.attachThreads = false;
final threadCount = fixture.eventWithPlatformStackTrace.threads?.length;
final platformExceptionEvent = await fixture.processor
.apply(fixture.eventWithPlatformStackTrace, Hint());
final exceptions = platformExceptionEvent!.exceptions!;
expect(exceptions.length, 3);
expect(platformExceptionEvent.threads?.length, threadCount);
});
test('does nothing if no PlatformException is there', () async {
final exception = fixture.options.exceptionFactory
.getSentryException(testPlatformException);
final event = SentryEvent(
exceptions: [exception],
throwable: null,
);
final platformExceptionEvent =
await fixture.processor.apply(event, Hint());
expect(event, platformExceptionEvent);
});
test('does nothing if PlatformException has no stackTrace', () async {
final platformExceptionEvent = await fixture.processor
.apply(fixture.eventWithoutPlatformStackTrace, Hint());
expect(fixture.eventWithoutPlatformStackTrace, platformExceptionEvent);
});
});
}
class Fixture {
late AndroidPlatformExceptionEventProcessor processor =
AndroidPlatformExceptionEventProcessor(options);
late SentryException withPlatformStackTrace = options.exceptionFactory
.getSentryException(testPlatformException)
.copyWith(threadId: 1);
late SentryException withoutPlatformStackTrace = options.exceptionFactory
.getSentryException(emptyPlatformException)
.copyWith(threadId: 1);
late SentryEvent eventWithPlatformStackTrace = SentryEvent(
exceptions: [withPlatformStackTrace],
throwable: testPlatformException,
threads: [dartThread],
);
late SentryEvent eventWithoutPlatformStackTrace = SentryEvent(
exceptions: [withoutPlatformStackTrace],
throwable: emptyPlatformException,
threads: [dartThread],
);
late SentryException withFailingPlatformStackTrace = options.exceptionFactory
.getSentryException(failingPlatformException)
.copyWith(threadId: 1);
late SentryEvent eventWithFailingPlatformStackTrace = SentryEvent(
exceptions: [withFailingPlatformStackTrace],
throwable: failingPlatformException,
threads: [dartThread],
);
late SentryThread dartThread = SentryThread(
crashed: true,
current: true,
id: 1,
name: 'main',
);
SentryFlutterOptions options = SentryFlutterOptions(dsn: fakeDsn)
..attachThreads = true;
}
final testPlatformException = PlatformException(
code: 'error',
details:
"Unsupported value: '[Ljava.lang.StackTraceElement;@fa902f1' of type 'class [Ljava.lang.StackTraceElement;'",
message: _jvmStackTrace,
stacktrace: _jvmStackTrace,
);
final emptyPlatformException = PlatformException(
code: 'error',
details:
"Unsupported value: '[Ljava.lang.StackTraceElement;@fa902f1' of type 'class [Ljava.lang.StackTraceElement;'",
message: null,
stacktrace: null,
);
final failingPlatformException = PlatformException(
code: 'error',
details:
"PlatformException: PlatformException(getNotificationChannelsError, Unable to find resource ID #0x7f14000d, android.content.res.Resources\$NotFoundException: Unable to find resource ID #0x7f14000d",
message: _failingStackTrace,
stacktrace: _failingStackTrace,
);
const _jvmStackTrace =
"""java.lang.IllegalArgumentException: Unsupported value: '[Ljava.lang.StackTraceElement;@ba6feed' of type 'class [Ljava.lang.StackTraceElement;'
at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:292)
at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:59)
at io.flutter.plugin.common.MethodChannel\$IncomingMethodCallHandler\$1.success(MethodChannel.java:267)
at io.sentry.samples.flutter.MainActivity.configureFlutterEngine\$lambda-0(MainActivity.kt:40)
at io.sentry.samples.flutter.MainActivity.lambda\$TiSaAm1LIEmKLVswI4BlR_5sw5Y(Unknown Source:0)
at io.sentry.samples.flutter.-\$\$Lambda\$MainActivity\$TiSaAm1LIEmKLVswI4BlR_5sw5Y.onMethodCall(Unknown Source:2)
at io.flutter.plugin.common.MethodChannel\$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
at io.flutter.embedding.engine.dart.DartMessenger.lambda\$dispatchMessageToQueue\$0\$DartMessenger(DartMessenger.java:320)
at io.flutter.embedding.engine.dart.-\$\$Lambda\$DartMessenger\$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8138)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)""";
const _failingStackTrace =
"""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)""";