Skip to content

Commit 689d2fd

Browse files
denrasemarandaneto
andauthored
Fix: Checks in some tests broken (#1315)
Co-authored-by: Manoel Aranda Neto <[email protected]> Co-authored-by: Manoel Aranda Neto <[email protected]>
1 parent 333903e commit 689d2fd

14 files changed

+250
-96
lines changed

dart/lib/src/hub.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class Hub {
273273
exception: exception,
274274
stackTrace: stackTrace,
275275
);
276+
if (_options.devMode) {
277+
rethrow;
278+
}
276279
}
277280
}
278281
return scope;
@@ -367,6 +370,9 @@ class Hub {
367370
SentryLevel.error,
368371
"Error in the 'configureScope' callback, error: $err",
369372
);
373+
if (_options.devMode) {
374+
rethrow;
375+
}
370376
}
371377
}
372378
}

dart/lib/src/scope.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ class Scope {
171171
exception: exception,
172172
stackTrace: stackTrace,
173173
);
174+
if (_options.devMode) {
175+
rethrow;
176+
}
174177
}
175178
}
176179
if (processedBreadcrumb != null) {
@@ -329,6 +332,9 @@ class Scope {
329332
exception: exception,
330333
stackTrace: stackTrace,
331334
);
335+
if (_options.devMode) {
336+
rethrow;
337+
}
332338
}
333339
if (processedEvent == null) {
334340
_options.logger(SentryLevel.debug, 'Event was dropped by a processor');

dart/lib/src/sentry.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Sentry {
4343
@internal SentryOptions? options,
4444
}) async {
4545
final sentryOptions = options ?? SentryOptions();
46+
4647
await _initDefaultValues(sentryOptions);
4748

4849
try {
@@ -57,6 +58,9 @@ class Sentry {
5758
exception: exception,
5859
stackTrace: stackTrace,
5960
);
61+
if (sentryOptions.devMode) {
62+
rethrow;
63+
}
6064
}
6165

6266
if (sentryOptions.dsn == null) {

dart/lib/src/sentry_client.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class SentryClient {
395395
exception: exception,
396396
stackTrace: stackTrace,
397397
);
398+
if (_options.devMode) {
399+
rethrow;
400+
}
398401
}
399402

400403
if (eventOrTransaction == null) {
@@ -429,6 +432,9 @@ class SentryClient {
429432
exception: exception,
430433
stackTrace: stackTrace,
431434
);
435+
if (_options.devMode) {
436+
rethrow;
437+
}
432438
}
433439
if (processedEvent == null) {
434440
_recordLostEvent(event, DiscardReason.eventProcessor);

dart/lib/src/sentry_options.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ class SentryOptions {
343343
_extractorsByType[extractor.exceptionType] = extractor;
344344
}
345345

346+
/// Changed SDK behaviour when set to true:
347+
/// - Rethrow exceptions that occur in user provided closures
348+
@internal
349+
bool devMode = false;
350+
346351
SentryOptions({this.dsn, PlatformChecker? checker}) {
347352
if (checker != null) {
348353
platformChecker = checker;

dart/lib/src/sentry_traces_sampler.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class SentryTracesSampler {
3838
exception: exception,
3939
stackTrace: stackTrace,
4040
);
41+
if (_options.devMode) {
42+
rethrow;
43+
}
4144
}
4245
}
4346

dart/test/environment_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void main() {
2323
release: 'release-9.8.7',
2424
dist: 'bar',
2525
);
26+
options.devMode = true;
2627

2728
await Sentry.init(
2829
(options) => options,
@@ -43,6 +44,7 @@ void main() {
4344
release: 'release-9.8.7',
4445
dist: 'bar',
4546
);
47+
options.devMode = true;
4648

4749
await Sentry.init(
4850
(options) => options,

dart/test/event_processor/deduplication_event_processor_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ void main() {
7777

7878
final transport = MockTransport();
7979

80+
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
8081
await Sentry.init(
8182
(options) {
8283
options.dsn = fakeDsn;
8384
options.transport = transport;
8485
options.enableDeduplication = true;
8586
},
87+
options: options,
8688
);
8789

8890
// The test doesn't work if `outerTestMethod` is passed as

dart/test/event_processor/enricher/io_enricher_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,18 @@ void main() {
159159
});
160160

161161
test('$IoEnricherEventProcessor gets added on init', () async {
162-
late SentryOptions sentryOptions;
162+
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
163+
late SentryOptions configuredOptions;
163164
await Sentry.init(
164165
(options) {
165166
options.dsn = fakeDsn;
166-
sentryOptions = options;
167+
configuredOptions = options;
167168
},
169+
options: options,
168170
);
169171
await Sentry.close();
170172

171-
final ioEnricherCount = sentryOptions.eventProcessors
173+
final ioEnricherCount = configuredOptions.eventProcessors
172174
.whereType<IoEnricherEventProcessor>()
173175
.length;
174176
expect(ioEnricherCount, 1);

dart/test/initialization_test.dart

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,42 @@ void main() {
1414
});
1515

1616
test('async re-initilization', () async {
17-
await Sentry.init((options) {
18-
options.dsn = fakeDsn;
19-
});
17+
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
18+
await Sentry.init(
19+
(options) {
20+
options.dsn = fakeDsn;
21+
},
22+
options: options,
23+
);
2024

2125
await Sentry.close();
2226

23-
await Sentry.init((options) {
24-
options.dsn = fakeDsn;
25-
});
27+
await Sentry.init(
28+
(options) {
29+
options.dsn = fakeDsn;
30+
},
31+
options: options,
32+
);
2633
});
2734

2835
// This is the failure from
2936
// https://github.com/getsentry/sentry-dart/issues/508
3037
test('re-initilization', () async {
31-
await Sentry.init((options) {
32-
options.dsn = fakeDsn;
33-
});
38+
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
39+
await Sentry.init(
40+
(options) {
41+
options.dsn = fakeDsn;
42+
},
43+
options: options,
44+
);
3445

3546
await Sentry.close();
3647

37-
await Sentry.init((options) {
38-
options.dsn = fakeDsn;
39-
});
48+
await Sentry.init(
49+
(options) {
50+
options.dsn = fakeDsn;
51+
},
52+
options: options,
53+
);
4054
});
4155
}

0 commit comments

Comments
 (0)