Skip to content

Commit

Permalink
Fix: Checks in some tests broken (#1315)
Browse files Browse the repository at this point in the history
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
Co-authored-by: Manoel Aranda Neto <marandaneto@gmail.com>
  • Loading branch information
3 people authored Mar 15, 2023
1 parent 333903e commit 689d2fd
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 96 deletions.
6 changes: 6 additions & 0 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.devMode) {
rethrow;
}
}
}
return scope;
Expand Down Expand Up @@ -367,6 +370,9 @@ class Hub {
SentryLevel.error,
"Error in the 'configureScope' callback, error: $err",
);
if (_options.devMode) {
rethrow;
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class Scope {
exception: exception,
stackTrace: stackTrace,
);
if (_options.devMode) {
rethrow;
}
}
}
if (processedBreadcrumb != null) {
Expand Down Expand Up @@ -329,6 +332,9 @@ class Scope {
exception: exception,
stackTrace: stackTrace,
);
if (_options.devMode) {
rethrow;
}
}
if (processedEvent == null) {
_options.logger(SentryLevel.debug, 'Event was dropped by a processor');
Expand Down
4 changes: 4 additions & 0 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Sentry {
@internal SentryOptions? options,
}) async {
final sentryOptions = options ?? SentryOptions();

await _initDefaultValues(sentryOptions);

try {
Expand All @@ -57,6 +58,9 @@ class Sentry {
exception: exception,
stackTrace: stackTrace,
);
if (sentryOptions.devMode) {
rethrow;
}
}

if (sentryOptions.dsn == null) {
Expand Down
6 changes: 6 additions & 0 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ class SentryClient {
exception: exception,
stackTrace: stackTrace,
);
if (_options.devMode) {
rethrow;
}
}

if (eventOrTransaction == null) {
Expand Down Expand Up @@ -429,6 +432,9 @@ class SentryClient {
exception: exception,
stackTrace: stackTrace,
);
if (_options.devMode) {
rethrow;
}
}
if (processedEvent == null) {
_recordLostEvent(event, DiscardReason.eventProcessor);
Expand Down
5 changes: 5 additions & 0 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ class SentryOptions {
_extractorsByType[extractor.exceptionType] = extractor;
}

/// Changed SDK behaviour when set to true:
/// - Rethrow exceptions that occur in user provided closures
@internal
bool devMode = false;

SentryOptions({this.dsn, PlatformChecker? checker}) {
if (checker != null) {
platformChecker = checker;
Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/sentry_traces_sampler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class SentryTracesSampler {
exception: exception,
stackTrace: stackTrace,
);
if (_options.devMode) {
rethrow;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions dart/test/environment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void main() {
release: 'release-9.8.7',
dist: 'bar',
);
options.devMode = true;

await Sentry.init(
(options) => options,
Expand All @@ -43,6 +44,7 @@ void main() {
release: 'release-9.8.7',
dist: 'bar',
);
options.devMode = true;

await Sentry.init(
(options) => options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ void main() {

final transport = MockTransport();

final options = SentryOptions(dsn: fakeDsn)..devMode = true;
await Sentry.init(
(options) {
options.dsn = fakeDsn;
options.transport = transport;
options.enableDeduplication = true;
},
options: options,
);

// The test doesn't work if `outerTestMethod` is passed as
Expand Down
8 changes: 5 additions & 3 deletions dart/test/event_processor/enricher/io_enricher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,18 @@ void main() {
});

test('$IoEnricherEventProcessor gets added on init', () async {
late SentryOptions sentryOptions;
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
late SentryOptions configuredOptions;
await Sentry.init(
(options) {
options.dsn = fakeDsn;
sentryOptions = options;
configuredOptions = options;
},
options: options,
);
await Sentry.close();

final ioEnricherCount = sentryOptions.eventProcessors
final ioEnricherCount = configuredOptions.eventProcessors
.whereType<IoEnricherEventProcessor>()
.length;
expect(ioEnricherCount, 1);
Expand Down
38 changes: 26 additions & 12 deletions dart/test/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,42 @@ void main() {
});

test('async re-initilization', () async {
await Sentry.init((options) {
options.dsn = fakeDsn;
});
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
await Sentry.init(
(options) {
options.dsn = fakeDsn;
},
options: options,
);

await Sentry.close();

await Sentry.init((options) {
options.dsn = fakeDsn;
});
await Sentry.init(
(options) {
options.dsn = fakeDsn;
},
options: options,
);
});

// This is the failure from
// https://github.com/getsentry/sentry-dart/issues/508
test('re-initilization', () async {
await Sentry.init((options) {
options.dsn = fakeDsn;
});
final options = SentryOptions(dsn: fakeDsn)..devMode = true;
await Sentry.init(
(options) {
options.dsn = fakeDsn;
},
options: options,
);

await Sentry.close();

await Sentry.init((options) {
options.dsn = fakeDsn;
});
await Sentry.init(
(options) {
options.dsn = fakeDsn;
},
options: options,
);
});
}
Loading

0 comments on commit 689d2fd

Please sign in to comment.