Skip to content

Commit

Permalink
Improve SentryException#value, remove stringified stack trace (#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored May 31, 2023
1 parent fcd1ee4 commit 8932ece
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Improve `SentryException#value`, remove stringified stack trace ([##1470](https://github.com/getsentry/sentry-dart/pull/#1470))

## 7.6.3

### Fixes
Expand Down
6 changes: 5 additions & 1 deletion dart/lib/src/sentry_exception_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ class SentryExceptionFactory {
}
}

final throwableString = throwable.toString();
final stackTraceString = stackTrace.toString();
final value = throwableString.replaceAll(stackTraceString, '').trim();

// if --obfuscate feature is enabled, 'type' won't be human readable.
// https://flutter.dev/docs/deployment/obfuscate#caveat
return SentryException(
type: (throwable.runtimeType).toString(),
value: throwable.toString(),
value: value.isNotEmpty ? value : null,
mechanism: mechanism,
stackTrace: sentryStackTrace,
throwable: throwable,
Expand Down
78 changes: 78 additions & 0 deletions dart/test/sentry_exception_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ void main() {

expect(sentryException.throwable, throwable);
});

test('should remove stackTrace string from value', () {
final stackTraceError = StackTraceError();
final sentryException = fixture.getSut().getSentryException(stackTraceError,
stackTrace: StackTraceErrorStackTrace());
final expected =
"NetworkError(type: NetworkErrorType.unknown, error: Instance of 'iH')";

expect(sentryException.value, expected);
});

test('no empty value', () {
final stackTraceError = StackTraceError();
stackTraceError.prefix = "";
final sentryException = fixture.getSut().getSentryException(stackTraceError,
stackTrace: StackTraceErrorStackTrace());

expect(sentryException.value, isNull);
});
}

class CustomError extends Error {}
Expand All @@ -187,6 +206,65 @@ class CustomExceptionStackTraceExtractor
}
}

class StackTraceError extends Error {
var prefix =
"NetworkError(type: NetworkErrorType.unknown, error: Instance of 'iH')";

@override
String toString() {
return '''
$prefix
pid: 9437, tid: 10069, name 1.ui
os: android arch: arm64 comp: yes sim: no
build_id: 'bca64abfdfcc84d231bb8f1ccdbfbd8d'
isolate_dso_base: 752602b000, vm_dso_base: 752602b000
isolate_instructions: 7526344980, vm_instructions: 752633f000
#00 abs 00000075266c2fbf virt 0000000000697fbf _kDartIsolateSnapshotInstructions+0x37e63f
#1 abs 000000752685211f virt 000000000082711f _kDartIsolateSnapshotInstructions+0x50d79f
#2 abs 0000007526851cb3 virt 0000000000826cb3 _kDartIsolateSnapshotInstructions+0x50d333
#3 abs 0000007526851c63 virt 0000000000826c63 _kDartIsolateSnapshotInstructions+0x50d2e3
#4 abs 0000007526851bf3 virt 0000000000826bf3 _kDartIsolateSnapshotInstructions+0x50d273
#5 abs 0000007526a0b44b virt 00000000009e044b _kDartIsolateSnapshotInstructions+0x6c6acb
#6 abs 0000007526a068a7 virt 00000000009db8a7 _kDartIsolateSnapshotInstructions+0x6c1f27
#7 abs 0000007526b57a2b virt 0000000000b2ca2b _kDartIsolateSnapshotInstructions+0x8130ab
#8 abs 0000007526b5d93b virt 0000000000b3293b _kDartIsolateSnapshotInstructions+0x818fbb
#9 abs 0000007526a2333b virt 00000000009f833b _kDartIsolateSnapshotInstructions+0x6de9bb
#10 abs 0000007526937957 virt 000000000090c957 _kDartIsolateSnapshotInstructions+0x5f2fd7
#11 abs 0000007526a243a3 virt 00000000009f93a3 _kDartIsolateSnapshotInstructions+0x6dfa23
#12 abs 000000752636273b virt 000000000033773b _kDartIsolateSnapshotInstructions+0x1ddbb
#13 abs 0000007526a36ac3 virt 0000000000a0bac3 _kDartIsolateSnapshotInstructions+0x6f2143
#14 abs 00000075263626af virt 00000000003376af _kDartIsolateSnapshotInstructions+0x1dd2f''';
}
}

class StackTraceErrorStackTrace extends StackTrace {
@override
String toString() {
return '''
pid: 9437, tid: 10069, name 1.ui
os: android arch: arm64 comp: yes sim: no
build_id: 'bca64abfdfcc84d231bb8f1ccdbfbd8d'
isolate_dso_base: 752602b000, vm_dso_base: 752602b000
isolate_instructions: 7526344980, vm_instructions: 752633f000
#00 abs 00000075266c2fbf virt 0000000000697fbf _kDartIsolateSnapshotInstructions+0x37e63f
#1 abs 000000752685211f virt 000000000082711f _kDartIsolateSnapshotInstructions+0x50d79f
#2 abs 0000007526851cb3 virt 0000000000826cb3 _kDartIsolateSnapshotInstructions+0x50d333
#3 abs 0000007526851c63 virt 0000000000826c63 _kDartIsolateSnapshotInstructions+0x50d2e3
#4 abs 0000007526851bf3 virt 0000000000826bf3 _kDartIsolateSnapshotInstructions+0x50d273
#5 abs 0000007526a0b44b virt 00000000009e044b _kDartIsolateSnapshotInstructions+0x6c6acb
#6 abs 0000007526a068a7 virt 00000000009db8a7 _kDartIsolateSnapshotInstructions+0x6c1f27
#7 abs 0000007526b57a2b virt 0000000000b2ca2b _kDartIsolateSnapshotInstructions+0x8130ab
#8 abs 0000007526b5d93b virt 0000000000b3293b _kDartIsolateSnapshotInstructions+0x818fbb
#9 abs 0000007526a2333b virt 00000000009f833b _kDartIsolateSnapshotInstructions+0x6de9bb
#10 abs 0000007526937957 virt 000000000090c957 _kDartIsolateSnapshotInstructions+0x5f2fd7
#11 abs 0000007526a243a3 virt 00000000009f93a3 _kDartIsolateSnapshotInstructions+0x6dfa23
#12 abs 000000752636273b virt 000000000033773b _kDartIsolateSnapshotInstructions+0x1ddbb
#13 abs 0000007526a36ac3 virt 0000000000a0bac3 _kDartIsolateSnapshotInstructions+0x6f2143
#14 abs 00000075263626af virt 00000000003376af _kDartIsolateSnapshotInstructions+0x1dd2f''';
}
}

class Fixture {
final options = SentryOptions(dsn: fakeDsn);

Expand Down

0 comments on commit 8932ece

Please sign in to comment.