Skip to content

Commit

Permalink
Discard empty stack frames (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored Sep 11, 2023
1 parent df7b257 commit 9d43f71
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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

### Dependencies
Expand Down
8 changes: 6 additions & 2 deletions flutter/lib/src/jvm/jvm_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ class JvmException {
frames.add(trimmed);
}

final thisExceptionFrames =
thisException.map((e) => JvmFrame.parse(e)).toList(growable: false);
final thisExceptionFrames = thisException
// Sometimes stringified exceptions from the native side have
// empty lines. Discard those!
.where((line) => line.trim().isNotEmpty)
.map((e) => JvmFrame.parse(e))
.toList(growable: false);

final suppressedExceptions = supressed
.map((e) => JvmException.parse(e.join(_newLine)))
Expand Down
30 changes: 29 additions & 1 deletion flutter/test/jvm/jvm_exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
'Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]');
expect(thirdCause.thread, null);
expect(thirdCause.type, 'java.sql.SQLException');
expect(thirdCause.stackTrace.length, 6);
expect(thirdCause.stackTrace.length, 5);
expect(thirdCause.causes, null);
expect(thirdCause.suppressed, null);
});
Expand Down Expand Up @@ -85,6 +85,16 @@ void main() {
expect(exception.stackTrace[0].fileName, 'StandardMessageCodec.java');
expect(exception.stackTrace[0].lineNumber, 292);
});

test('parse drops empty frames', () {
final exception = JvmException.parse(platformExceptionWithEmptyStackFrames);
expect(exception.stackTrace.length, 13);
expect(exception.stackTrace.last.className,
'com.android.internal.os.ZygoteInit');
expect(exception.stackTrace.last.fileName, 'ZygoteInit.java');
expect(exception.stackTrace.last.method, 'main');
expect(exception.stackTrace.last.lineNumber, 936);
});
}

const javaExceptionWithCauses = '''
Expand Down Expand Up @@ -194,3 +204,21 @@ java.lang.IllegalArgumentException: Unsupported value: '[Ljava.lang.StackTraceEl
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 platformExceptionWithEmptyStackFrames = '''
java.lang.RuntimeException: Catch this platform exception!
at io.sentry.samples.flutter.MainActivity\$configureFlutterEngine\$1.onMethodCall(MainActivity.kt:40)
at io.flutter.plugin.common.MethodChannel\$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda\$dispatchMessageToQueue\$0\$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
at io.flutter.embedding.engine.dart.DartMessenger\$\$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit\$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
''';
1 change: 1 addition & 0 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ class _MockHub extends MockHub {
@override
final options = SentryOptions(dsn: fakeDsn);

@override
late final scope = Scope(options);

@override
Expand Down
15 changes: 11 additions & 4 deletions sqflite/lib/src/sentry_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
@internal Hub? hub,
}) : _hub = hub ?? HubAdapter(),
dbName = p.basenameWithoutExtension(_database.path),
super(_database,
hub: hub, dbName: p.basenameWithoutExtension(_database.path)) {
super(
_database,
hub: hub,
dbName: p.basenameWithoutExtension(_database.path),
) {
// ignore: invalid_use_of_internal_member
final options = _hub.options;
options.sdk.addIntegration('SentrySqfliteTracing');
Expand Down Expand Up @@ -132,8 +135,12 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
setDatabaseAttributeData(span, dbName);

Future<T> newAction(Transaction txn) async {
final executor = SentryDatabaseExecutor(txn,
parentSpan: span, hub: _hub, dbName: dbName);
final executor = SentryDatabaseExecutor(
txn,
parentSpan: span,
hub: _hub,
dbName: dbName,
);
final sentrySqfliteTransaction =
SentrySqfliteTransaction(executor, hub: _hub, dbName: dbName);

Expand Down
3 changes: 2 additions & 1 deletion sqflite/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ ISentrySpan startTransactionShim(
],
customMocks: [
MockSpec<Hub>(
fallbackGenerators: {#startTransaction: startTransactionShim}),
fallbackGenerators: {#startTransaction: startTransactionShim},
),
],
)
void main() {}
8 changes: 6 additions & 2 deletions sqflite/test/sentry_batch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ SELECT * FROM Product''';
final span = fixture.tracer.children.last;
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
span.data[SentryDatabase.dbNameKey],
(db as SentryDatabase).dbName,
);

await db.close();
});
Expand All @@ -313,7 +315,9 @@ SELECT * FROM Product''';
final span = fixture.tracer.children.last;
expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
expect(
span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName);
span.data[SentryDatabase.dbNameKey],
(db as SentryDatabase).dbName,
);

await db.close();
});
Expand Down
4 changes: 3 additions & 1 deletion sqflite/test/sentry_database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ void main() {
expect(insertSpan.context.parentSpanId, trSpan.context.spanId);
expect(insertSpan.status, SpanStatus.ok());
expect(
insertSpan.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem);
insertSpan.data[SentryDatabase.dbSystemKey],
SentryDatabase.dbSystem,
);
expect(insertSpan.data[SentryDatabase.dbNameKey], inMemoryDatabasePath);

expect(
Expand Down

0 comments on commit 9d43f71

Please sign in to comment.