File tree Expand file tree Collapse file tree 8 files changed +65
-8
lines changed Expand file tree Collapse file tree 8 files changed +65
-8
lines changed Original file line number Diff line number Diff line change 7
7
- Merging of integrations and packages ([ #1111 ] ( https://github.com/getsentry/sentry-dart/pull/1111 ) )
8
8
- Add missing ` fragment ` for HTTP Client Errors ([ #1102 ] ( https://github.com/getsentry/sentry-dart/pull/1102 ) )
9
9
- Sync user name and geo for Android ([ #1102 ] ( https://github.com/getsentry/sentry-dart/pull/1102 ) )
10
+ - Add mechanism to Dio Http Client error ([ #1114 ] ( https://github.com/getsentry/sentry-dart/pull/1114 ) )
10
11
11
12
### Dependencies
12
13
Original file line number Diff line number Diff line change @@ -126,8 +126,7 @@ class FailedRequestClient extends BaseClient {
126
126
} else if (failedRequestStatusCodes.containsStatusCode (statusCode)) {
127
127
// Capture an exception if the status code is considered bad
128
128
capture = true ;
129
- reason =
130
- 'Event was captured because the request status code was $statusCode ' ;
129
+ reason = 'HTTP Client Error with status code: $statusCode ' ;
131
130
exception ?? = SentryHttpClientError (reason);
132
131
}
133
132
if (capture) {
@@ -184,7 +183,17 @@ class FailedRequestClient extends BaseClient {
184
183
type: 'SentryHttpClient' ,
185
184
description: reason,
186
185
);
187
- final throwableMechanism = ThrowableMechanism (mechanism, exception);
186
+
187
+ bool ? snapshot;
188
+ if (exception is SentryHttpClientError ) {
189
+ snapshot = true ;
190
+ }
191
+
192
+ final throwableMechanism = ThrowableMechanism (
193
+ mechanism,
194
+ exception,
195
+ snapshot: snapshot,
196
+ );
188
197
189
198
final event = SentryEvent (
190
199
throwable: throwableMechanism,
Original file line number Diff line number Diff line change @@ -17,9 +17,11 @@ class SentryExceptionFactory {
17
17
}) {
18
18
var throwable = exception;
19
19
Mechanism ? mechanism;
20
+ bool ? snapshot;
20
21
if (exception is ThrowableMechanism ) {
21
22
throwable = exception.throwable;
22
23
mechanism = exception.mechanism;
24
+ snapshot = exception.snapshot;
23
25
}
24
26
25
27
if (throwable is Error ) {
@@ -29,6 +31,8 @@ class SentryExceptionFactory {
29
31
// hence we check again if stackTrace is null and if not, read the current stack trace
30
32
// but only if attachStacktrace is enabled
31
33
if (_options.attachStacktrace) {
34
+ // TODO: snapshot=true if stackTrace is null
35
+ // Requires a major breaking change because of grouping
32
36
stackTrace ?? = StackTrace .current;
33
37
}
34
38
@@ -39,6 +43,7 @@ class SentryExceptionFactory {
39
43
if (frames.isNotEmpty) {
40
44
sentryStackTrace = SentryStackTrace (
41
45
frames: frames,
46
+ snapshot: snapshot,
42
47
);
43
48
}
44
49
}
Original file line number Diff line number Diff line change @@ -4,10 +4,17 @@ import 'protocol/mechanism.dart';
4
4
class ThrowableMechanism implements Exception {
5
5
final Mechanism _mechanism;
6
6
final dynamic _throwable;
7
+ final bool ? _snapshot;
7
8
8
- ThrowableMechanism (this ._mechanism, this ._throwable);
9
+ ThrowableMechanism (
10
+ this ._mechanism,
11
+ this ._throwable, {
12
+ bool ? snapshot,
13
+ }) : _snapshot = snapshot;
9
14
10
15
Mechanism get mechanism => _mechanism;
11
16
12
17
dynamic get throwable => _throwable;
18
+
19
+ bool ? get snapshot => _snapshot;
13
20
}
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ void main() {
48
48
final mechanism = exception? .mechanism;
49
49
50
50
expect (exception? .stackTrace, isNotNull);
51
+ expect (exception? .stackTrace! .snapshot, isNull);
51
52
expect (mechanism? .type, 'SentryHttpClient' );
52
53
53
54
final request = eventCall.request;
@@ -101,14 +102,15 @@ void main() {
101
102
expect (mechanism? .type, 'SentryHttpClient' );
102
103
expect (
103
104
mechanism? .description,
104
- 'Event was captured because the request status code was 404' ,
105
+ 'HTTP Client Error with status code: 404' ,
105
106
);
106
107
107
108
expect (exception? .type, 'SentryHttpClientError' );
108
109
expect (
109
110
exception? .value,
110
- 'Exception: Event was captured because the request status code was 404' ,
111
+ 'Exception: HTTP Client Error with status code: 404' ,
111
112
);
113
+ expect (exception? .stackTrace? .snapshot, true );
112
114
113
115
final request = eventCall.request;
114
116
expect (request, isNotNull);
Original file line number Diff line number Diff line change @@ -83,6 +83,28 @@ void main() {
83
83
84
84
// skip on browser because [StackTrace.current] still returns null
85
85
}, onPlatform: {'browser' : Skip ()});
86
+
87
+ test ('reads the snapshot from the mechanism' , () {
88
+ final error = StateError ('test-error' );
89
+ final mechanism = Mechanism (type: 'Mechanism' );
90
+ final throwableMechanism = ThrowableMechanism (
91
+ mechanism,
92
+ error,
93
+ snapshot: true ,
94
+ );
95
+
96
+ SentryException sentryException;
97
+ try {
98
+ throw throwableMechanism;
99
+ } catch (err, stackTrace) {
100
+ sentryException = fixture.getSut ().getSentryException (
101
+ throwableMechanism,
102
+ stackTrace: stackTrace,
103
+ );
104
+ }
105
+
106
+ expect (sentryException.stackTrace! .snapshot, true );
107
+ });
86
108
}
87
109
88
110
class CustomError extends Error {}
Original file line number Diff line number Diff line change @@ -13,8 +13,12 @@ class FailedRequestInterceptor extends Interceptor {
13
13
DioError err,
14
14
ErrorInterceptorHandler handler,
15
15
) async {
16
+ final mechanism = Mechanism (type: 'SentryDioClientAdapter' );
17
+ final throwableMechanism = ThrowableMechanism (mechanism, err);
18
+
16
19
_hub.getSpan ()? .throwable = err;
17
- await _hub.captureException (err);
20
+
21
+ await _hub.captureException (throwableMechanism);
18
22
19
23
handler.next (err);
20
24
}
Original file line number Diff line number Diff line change 1
1
import 'package:dio/dio.dart' ;
2
+ import 'package:sentry/sentry.dart' ;
2
3
import 'package:sentry_dio/src/failed_request_interceptor.dart' ;
3
4
import 'package:test/test.dart' ;
4
5
@@ -14,13 +15,19 @@ void main() {
14
15
15
16
test ('interceptor send error' , () async {
16
17
final interceptor = fixture.getSut ();
18
+ final error = DioError (requestOptions: RequestOptions (path: '' ));
17
19
await interceptor.onError (
18
- DioError (requestOptions : RequestOptions (path : '' )) ,
20
+ error ,
19
21
fixture.errorInterceptorHandler,
20
22
);
21
23
22
24
expect (fixture.errorInterceptorHandler.nextWasCalled, true );
23
25
expect (fixture.hub.captureExceptionCalls.length, 1 );
26
+
27
+ final throwable =
28
+ fixture.hub.captureExceptionCalls.first.throwable as ThrowableMechanism ;
29
+ expect (throwable.mechanism.type, 'SentryDioClientAdapter' );
30
+ expect (throwable.throwable, error);
24
31
});
25
32
}
26
33
You can’t perform that action at this time.
0 commit comments