Skip to content

Commit 9d43f71

Browse files
authored
Discard empty stack frames (#1625)
1 parent df7b257 commit 9d43f71

File tree

8 files changed

+59
-11
lines changed

8 files changed

+59
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
- Normalize data properties of `SentryUser` and `Breadcrumb` before sending over method channel ([#1591](https://github.com/getsentry/sentry-dart/pull/1591))
1717
- Fixing memory leak issue in SentryFlutterPlugin (Android Plugin) ([#1588](https://github.com/getsentry/sentry-dart/pull/1588))
18+
- Discard empty stack frames ([#1625](https://github.com/getsentry/sentry-dart/pull/1625))
1819
- Disable scope sync for cloned scopes ([#1628](https://github.com/getsentry/sentry-dart/pull/1628))
1920

2021
### Dependencies

flutter/lib/src/jvm/jvm_exception.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,12 @@ class JvmException {
256256
frames.add(trimmed);
257257
}
258258

259-
final thisExceptionFrames =
260-
thisException.map((e) => JvmFrame.parse(e)).toList(growable: false);
259+
final thisExceptionFrames = thisException
260+
// Sometimes stringified exceptions from the native side have
261+
// empty lines. Discard those!
262+
.where((line) => line.trim().isNotEmpty)
263+
.map((e) => JvmFrame.parse(e))
264+
.toList(growable: false);
261265

262266
final suppressedExceptions = supressed
263267
.map((e) => JvmException.parse(e.join(_newLine)))

flutter/test/jvm/jvm_exception_test.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
'Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]');
4141
expect(thirdCause.thread, null);
4242
expect(thirdCause.type, 'java.sql.SQLException');
43-
expect(thirdCause.stackTrace.length, 6);
43+
expect(thirdCause.stackTrace.length, 5);
4444
expect(thirdCause.causes, null);
4545
expect(thirdCause.suppressed, null);
4646
});
@@ -85,6 +85,16 @@ void main() {
8585
expect(exception.stackTrace[0].fileName, 'StandardMessageCodec.java');
8686
expect(exception.stackTrace[0].lineNumber, 292);
8787
});
88+
89+
test('parse drops empty frames', () {
90+
final exception = JvmException.parse(platformExceptionWithEmptyStackFrames);
91+
expect(exception.stackTrace.length, 13);
92+
expect(exception.stackTrace.last.className,
93+
'com.android.internal.os.ZygoteInit');
94+
expect(exception.stackTrace.last.fileName, 'ZygoteInit.java');
95+
expect(exception.stackTrace.last.method, 'main');
96+
expect(exception.stackTrace.last.lineNumber, 936);
97+
});
8898
}
8999

90100
const javaExceptionWithCauses = '''
@@ -194,3 +204,21 @@ java.lang.IllegalArgumentException: Unsupported value: '[Ljava.lang.StackTraceEl
194204
at java.lang.reflect.Method.invoke(Native Method)
195205
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:556)
196206
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)''';
207+
208+
const platformExceptionWithEmptyStackFrames = '''
209+
java.lang.RuntimeException: Catch this platform exception!
210+
at io.sentry.samples.flutter.MainActivity\$configureFlutterEngine\$1.onMethodCall(MainActivity.kt:40)
211+
at io.flutter.plugin.common.MethodChannel\$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
212+
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
213+
at io.flutter.embedding.engine.dart.DartMessenger.lambda\$dispatchMessageToQueue\$0\$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
214+
at io.flutter.embedding.engine.dart.DartMessenger\$\$ExternalSyntheticLambda0.run(Unknown Source:12)
215+
at android.os.Handler.handleCallback(Handler.java:942)
216+
at android.os.Handler.dispatchMessage(Handler.java:99)
217+
at android.os.Looper.loopOnce(Looper.java:201)
218+
at android.os.Looper.loop(Looper.java:288)
219+
at android.app.ActivityThread.main(ActivityThread.java:7872)
220+
at java.lang.reflect.Method.invoke
221+
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:548)
222+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
223+
224+
''';

flutter/test/sentry_navigator_observer_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ class _MockHub extends MockHub {
756756
@override
757757
final options = SentryOptions(dsn: fakeDsn);
758758

759+
@override
759760
late final scope = Scope(options);
760761

761762
@override

sqflite/lib/src/sentry_database.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
5858
@internal Hub? hub,
5959
}) : _hub = hub ?? HubAdapter(),
6060
dbName = p.basenameWithoutExtension(_database.path),
61-
super(_database,
62-
hub: hub, dbName: p.basenameWithoutExtension(_database.path)) {
61+
super(
62+
_database,
63+
hub: hub,
64+
dbName: p.basenameWithoutExtension(_database.path),
65+
) {
6366
// ignore: invalid_use_of_internal_member
6467
final options = _hub.options;
6568
options.sdk.addIntegration('SentrySqfliteTracing');
@@ -132,8 +135,12 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
132135
setDatabaseAttributeData(span, dbName);
133136

134137
Future<T> newAction(Transaction txn) async {
135-
final executor = SentryDatabaseExecutor(txn,
136-
parentSpan: span, hub: _hub, dbName: dbName);
138+
final executor = SentryDatabaseExecutor(
139+
txn,
140+
parentSpan: span,
141+
hub: _hub,
142+
dbName: dbName,
143+
);
137144
final sentrySqfliteTransaction =
138145
SentrySqfliteTransaction(executor, hub: _hub, dbName: dbName);
139146

sqflite/test/mocks/mocks.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ ISentrySpan startTransactionShim(
3434
],
3535
customMocks: [
3636
MockSpec<Hub>(
37-
fallbackGenerators: {#startTransaction: startTransactionShim}),
37+
fallbackGenerators: {#startTransaction: startTransactionShim},
38+
),
3839
],
3940
)
4041
void main() {}

sqflite/test/sentry_batch_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ SELECT * FROM Product''';
296296
final span = fixture.tracer.children.last;
297297
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
298298
expect(
299-
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
299+
span.data[SentryDatabase.dbNameKey],
300+
(db as SentryDatabase).dbName,
301+
);
300302

301303
await db.close();
302304
});
@@ -313,7 +315,9 @@ SELECT * FROM Product''';
313315
final span = fixture.tracer.children.last;
314316
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
315317
expect(
316-
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
318+
span.data[SentryDatabase.dbNameKey],
319+
(db as SentryDatabase).dbName,
320+
);
317321

318322
await db.close();
319323
});

sqflite/test/sentry_database_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ void main() {
112112
expect(insertSpan.context.parentSpanId, trSpan.context.spanId);
113113
expect(insertSpan.status, SpanStatus.ok());
114114
expect(
115-
insertSpan.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
115+
insertSpan.data[SentryDatabase.dbSystemKey],
116+
SentryDatabase.dbSystem,
117+
);
116118
expect(insertSpan.data[SentryDatabase.dbNameKey], inMemoryDatabasePath);
117119

118120
expect(

0 commit comments

Comments
 (0)