Skip to content

Commit 8932ece

Browse files
authored
Improve SentryException#value, remove stringified stack trace (#1470)
1 parent fcd1ee4 commit 8932ece

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Improve `SentryException#value`, remove stringified stack trace ([##1470](https://github.com/getsentry/sentry-dart/pull/#1470))
8+
39
## 7.6.3
410

511
### Fixes

dart/lib/src/sentry_exception_factory.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ class SentryExceptionFactory {
5757
}
5858
}
5959

60+
final throwableString = throwable.toString();
61+
final stackTraceString = stackTrace.toString();
62+
final value = throwableString.replaceAll(stackTraceString, '').trim();
63+
6064
// if --obfuscate feature is enabled, 'type' won't be human readable.
6165
// https://flutter.dev/docs/deployment/obfuscate#caveat
6266
return SentryException(
6367
type: (throwable.runtimeType).toString(),
64-
value: throwable.toString(),
68+
value: value.isNotEmpty ? value : null,
6569
mechanism: mechanism,
6670
stackTrace: sentryStackTrace,
6771
throwable: throwable,

dart/test/sentry_exception_factory_test.dart

+78
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ void main() {
169169

170170
expect(sentryException.throwable, throwable);
171171
});
172+
173+
test('should remove stackTrace string from value', () {
174+
final stackTraceError = StackTraceError();
175+
final sentryException = fixture.getSut().getSentryException(stackTraceError,
176+
stackTrace: StackTraceErrorStackTrace());
177+
final expected =
178+
"NetworkError(type: NetworkErrorType.unknown, error: Instance of 'iH')";
179+
180+
expect(sentryException.value, expected);
181+
});
182+
183+
test('no empty value', () {
184+
final stackTraceError = StackTraceError();
185+
stackTraceError.prefix = "";
186+
final sentryException = fixture.getSut().getSentryException(stackTraceError,
187+
stackTrace: StackTraceErrorStackTrace());
188+
189+
expect(sentryException.value, isNull);
190+
});
172191
}
173192

174193
class CustomError extends Error {}
@@ -187,6 +206,65 @@ class CustomExceptionStackTraceExtractor
187206
}
188207
}
189208

209+
class StackTraceError extends Error {
210+
var prefix =
211+
"NetworkError(type: NetworkErrorType.unknown, error: Instance of 'iH')";
212+
213+
@override
214+
String toString() {
215+
return '''
216+
$prefix
217+
218+
pid: 9437, tid: 10069, name 1.ui
219+
os: android arch: arm64 comp: yes sim: no
220+
build_id: 'bca64abfdfcc84d231bb8f1ccdbfbd8d'
221+
isolate_dso_base: 752602b000, vm_dso_base: 752602b000
222+
isolate_instructions: 7526344980, vm_instructions: 752633f000
223+
#00 abs 00000075266c2fbf virt 0000000000697fbf _kDartIsolateSnapshotInstructions+0x37e63f
224+
#1 abs 000000752685211f virt 000000000082711f _kDartIsolateSnapshotInstructions+0x50d79f
225+
#2 abs 0000007526851cb3 virt 0000000000826cb3 _kDartIsolateSnapshotInstructions+0x50d333
226+
#3 abs 0000007526851c63 virt 0000000000826c63 _kDartIsolateSnapshotInstructions+0x50d2e3
227+
#4 abs 0000007526851bf3 virt 0000000000826bf3 _kDartIsolateSnapshotInstructions+0x50d273
228+
#5 abs 0000007526a0b44b virt 00000000009e044b _kDartIsolateSnapshotInstructions+0x6c6acb
229+
#6 abs 0000007526a068a7 virt 00000000009db8a7 _kDartIsolateSnapshotInstructions+0x6c1f27
230+
#7 abs 0000007526b57a2b virt 0000000000b2ca2b _kDartIsolateSnapshotInstructions+0x8130ab
231+
#8 abs 0000007526b5d93b virt 0000000000b3293b _kDartIsolateSnapshotInstructions+0x818fbb
232+
#9 abs 0000007526a2333b virt 00000000009f833b _kDartIsolateSnapshotInstructions+0x6de9bb
233+
#10 abs 0000007526937957 virt 000000000090c957 _kDartIsolateSnapshotInstructions+0x5f2fd7
234+
#11 abs 0000007526a243a3 virt 00000000009f93a3 _kDartIsolateSnapshotInstructions+0x6dfa23
235+
#12 abs 000000752636273b virt 000000000033773b _kDartIsolateSnapshotInstructions+0x1ddbb
236+
#13 abs 0000007526a36ac3 virt 0000000000a0bac3 _kDartIsolateSnapshotInstructions+0x6f2143
237+
#14 abs 00000075263626af virt 00000000003376af _kDartIsolateSnapshotInstructions+0x1dd2f''';
238+
}
239+
}
240+
241+
class StackTraceErrorStackTrace extends StackTrace {
242+
@override
243+
String toString() {
244+
return '''
245+
pid: 9437, tid: 10069, name 1.ui
246+
os: android arch: arm64 comp: yes sim: no
247+
build_id: 'bca64abfdfcc84d231bb8f1ccdbfbd8d'
248+
isolate_dso_base: 752602b000, vm_dso_base: 752602b000
249+
isolate_instructions: 7526344980, vm_instructions: 752633f000
250+
#00 abs 00000075266c2fbf virt 0000000000697fbf _kDartIsolateSnapshotInstructions+0x37e63f
251+
#1 abs 000000752685211f virt 000000000082711f _kDartIsolateSnapshotInstructions+0x50d79f
252+
#2 abs 0000007526851cb3 virt 0000000000826cb3 _kDartIsolateSnapshotInstructions+0x50d333
253+
#3 abs 0000007526851c63 virt 0000000000826c63 _kDartIsolateSnapshotInstructions+0x50d2e3
254+
#4 abs 0000007526851bf3 virt 0000000000826bf3 _kDartIsolateSnapshotInstructions+0x50d273
255+
#5 abs 0000007526a0b44b virt 00000000009e044b _kDartIsolateSnapshotInstructions+0x6c6acb
256+
#6 abs 0000007526a068a7 virt 00000000009db8a7 _kDartIsolateSnapshotInstructions+0x6c1f27
257+
#7 abs 0000007526b57a2b virt 0000000000b2ca2b _kDartIsolateSnapshotInstructions+0x8130ab
258+
#8 abs 0000007526b5d93b virt 0000000000b3293b _kDartIsolateSnapshotInstructions+0x818fbb
259+
#9 abs 0000007526a2333b virt 00000000009f833b _kDartIsolateSnapshotInstructions+0x6de9bb
260+
#10 abs 0000007526937957 virt 000000000090c957 _kDartIsolateSnapshotInstructions+0x5f2fd7
261+
#11 abs 0000007526a243a3 virt 00000000009f93a3 _kDartIsolateSnapshotInstructions+0x6dfa23
262+
#12 abs 000000752636273b virt 000000000033773b _kDartIsolateSnapshotInstructions+0x1ddbb
263+
#13 abs 0000007526a36ac3 virt 0000000000a0bac3 _kDartIsolateSnapshotInstructions+0x6f2143
264+
#14 abs 00000075263626af virt 00000000003376af _kDartIsolateSnapshotInstructions+0x1dd2f''';
265+
}
266+
}
267+
190268
class Fixture {
191269
final options = SentryOptions(dsn: fakeDsn);
192270

0 commit comments

Comments
 (0)