Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bc65a42
Update dependencies + fix tests
ueman Feb 10, 2021
c6b35e0
Remove unused code
ueman Feb 10, 2021
4dc480b
Migration Hints
ueman Feb 10, 2021
88eb3c6
add more type annotations + make api more nullsafety friendly
ueman Feb 10, 2021
ff296d0
null safety migration
ueman Feb 10, 2021
35b663d
Rewritten test + fixed linter warnings
ueman Feb 13, 2021
713b05b
Fixed more test which were broken
ueman Feb 13, 2021
c24a96d
Fix tests
ueman Feb 14, 2021
d722a8c
Don't build CI on Dart stable
ueman Feb 14, 2021
437fc1c
Fixed test + some more null safety refactorings
ueman Feb 14, 2021
9133b3b
build flutter only on beta
ueman Feb 15, 2021
b15c136
fix example
ueman Feb 15, 2021
3d4a513
make sure the Flutter Sentry SDK compiles
ueman Feb 15, 2021
d594922
DebugImage.type is required -> non-nullable
ueman Feb 15, 2021
42a619c
add changelog
ueman Feb 15, 2021
5201270
Update dart/lib/src/sentry_options.dart
ueman Feb 17, 2021
a41c4a7
Merge remote-tracking branch 'upstream/main' into feature/nullsafety
ueman Feb 20, 2021
5276086
Apply improvements and suggestions from PR review
ueman Feb 20, 2021
39c6a2a
Use stable null safe release in Flutter
ueman Feb 20, 2021
9a7328b
Some smaller fixes
ueman Feb 20, 2021
5c0ddbf
use correct dart sdk
ueman Feb 20, 2021
95508d6
Use nullable lists/maps :(
ueman Feb 20, 2021
3638f43
fix
ueman Feb 20, 2021
44a8206
Update dart/lib/src/scope.dart
ueman Feb 22, 2021
3b2b6dd
Add PR feedback
ueman Feb 22, 2021
699b31a
Merge remote-tracking branch 'origin/feature/nullsafety' into feature…
ueman Feb 22, 2021
7635d4e
fix typo
ueman Feb 22, 2021
006fb0c
Merge remote-tracking branch 'upstream/feat/null-safety' into feature…
ueman Feb 22, 2021
1703333
fix problems caused by merge
ueman Feb 22, 2021
7ea8a89
PR Feedback
ueman Feb 23, 2021
1aacadb
Make SentryLevel nullable again
ueman Feb 23, 2021
7308de7
Remove default values
ueman Feb 23, 2021
83bc406
PR Feedback
ueman Feb 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
# TODO: cedx/setup-dart@v2 doesn't work on Windows (doesn't add pub to the PATH?)
# os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest]
sdk: [beta, dev, stable]
sdk: [beta, dev]
exclude:
# Bad state: Could not run tests with Observatory enabled. Try setting a different port with --port option.
- os: ubuntu-latest
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
steps:
- uses: cedx/setup-dart@v2
with:
release-channel: stable
release-channel: beta
- uses: actions/checkout@v2
- run: |
dart pub get
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
target: ['ios', 'android', 'web']
channel: ['stable', 'beta']
channel: ['beta']
exclude:
- os: ubuntu-latest
target: ios
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# vNext

* Refactoring: Migrate Sentry Dart to null safety
* Fix: captureMessage defaults SentryLevel to info

# 4.0.5
Expand Down
2 changes: 1 addition & 1 deletion dart/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Future<void> runApp() async {

print('Capture exception result : SentryId : $sentryId');
} finally {
await Sentry.close();
Sentry.close();
}
}

Expand Down
11 changes: 5 additions & 6 deletions dart/lib/src/http_client/sentry_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ import '../../sentry.dart';
// For example with Darts Stopwatch:
// https://api.dart.dev/stable/2.10.4/dart-core/Stopwatch-class.html
class SentryHttpClient extends BaseClient {
SentryHttpClient({Client client, Hub hub}) {
_hub = hub ?? HubAdapter();
_client = client ?? Client();
}
SentryHttpClient({Client? client, Hub? hub})
: _hub = hub ?? HubAdapter(),
_client = client ?? Client();

Client _client;
Hub _hub;
final Client _client;
final Hub _hub;

@override
Future<StreamedResponse> send(BaseRequest request) async {
Expand Down
191 changes: 64 additions & 127 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:collection';

import 'noop_sentry_client.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry_client.dart';
Expand All @@ -18,8 +17,9 @@ class Hub {

final ListQueue<_StackItem> _stack = ListQueue();

/// if stack is empty, it throws IterableElementError.noElement()
_StackItem _peek() => _stack.isNotEmpty ? _stack.first : null;
// peek can never return null since Stack can be created only with an item and
// pop does not drop the last item.
_StackItem _peek() => _stack.first;

final SentryOptions _options;

Expand All @@ -35,11 +35,7 @@ class Hub {
}

static void _validateOptions(SentryOptions options) {
if (options == null) {
throw ArgumentError('SentryOptions is required.');
}

if (options.dsn?.isNotEmpty != true) {
if (options.dsn == null) {
throw ArgumentError('DSN is required.');
}
}
Expand Down Expand Up @@ -67,34 +63,23 @@ class Hub {
SentryLevel.warning,
"Instance is disabled and this 'captureEvent' call is a no-op.",
);
} else if (event == null) {
_options.logger(
SentryLevel.warning,
'captureEvent called with null parameter.',
);
} else {
final item = _peek();
if (item != null) {
try {
sentryId = await item.client.captureEvent(
event,
stackTrace: stackTrace,
scope: item.scope,
hint: hint,
);
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while capturing event with id: ${event.eventId.toString()}',
);
} finally {
_lastEventId = sentryId;
}
} else {

try {
sentryId = await item.client.captureEvent(
event,
stackTrace: stackTrace,
scope: item.scope,
hint: hint,
);
} catch (err) {
_options.logger(
SentryLevel.fatal,
'Stack peek was null when captureEvent',
SentryLevel.error,
'Error while capturing event with id: ${event.eventId.toString()}',
);
} finally {
_lastEventId = sentryId;
}
}
return sentryId;
Expand All @@ -120,27 +105,21 @@ class Hub {
);
} else {
final item = _peek();
if (item != null) {
try {
sentryId = await item.client.captureException(
throwable,
stackTrace: stackTrace,
scope: item.scope,
hint: hint,
);
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while capturing exception : $throwable',
);
} finally {
_lastEventId = sentryId;
}
} else {

try {
sentryId = await item.client.captureException(
throwable,
stackTrace: stackTrace,
scope: item.scope,
hint: hint,
);
} catch (err) {
_options.logger(
SentryLevel.fatal,
'Stack peek was null when captureException',
SentryLevel.error,
'Error while capturing exception : $throwable',
);
} finally {
_lastEventId = sentryId;
}
}

Expand All @@ -149,10 +128,10 @@ class Hub {

/// Captures the message.
Future<SentryId> captureMessage(
String message, {
SentryLevel level,
String template,
List<dynamic> params,
String? message, {
SentryLevel? level,
String? template,
List<dynamic>? params,
dynamic hint,
}) async {
var sentryId = SentryId.empty();
Expand All @@ -169,29 +148,23 @@ class Hub {
);
} else {
final item = _peek();
if (item != null) {
try {
sentryId = await item.client.captureMessage(
message,
level: level,
template: template,
params: params,
scope: item.scope,
hint: hint,
);
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while capturing message with id: $message',
);
} finally {
_lastEventId = sentryId;
}
} else {

try {
sentryId = await item.client.captureMessage(
message,
level: level,
template: template,
params: params,
scope: item.scope,
hint: hint,
);
} catch (err) {
_options.logger(
SentryLevel.fatal,
'Stack peek was null when captureMessage',
SentryLevel.error,
'Error while capturing message with id: $message',
);
} finally {
_lastEventId = sentryId;
}
}
return sentryId;
Expand All @@ -204,21 +177,9 @@ class Hub {
SentryLevel.warning,
"Instance is disabled and this 'addBreadcrumb' call is a no-op.",
);
} else if (crumb == null) {
_options.logger(
SentryLevel.warning,
'addBreadcrumb called with null parameter.',
);
} else {
final item = _peek();
if (item != null) {
item.scope.addBreadcrumb(crumb, hint: hint);
} else {
_options.logger(
SentryLevel.fatal,
'Stack peek was null when addBreadcrumb',
);
}
item.scope.addBreadcrumb(crumb, hint: hint);
}
}

Expand All @@ -229,20 +190,8 @@ class Hub {
"Instance is disabled and this 'bindClient' call is a no-op.");
} else {
final item = _peek();
if (item != null) {
if (client != null) {
_options.logger(SentryLevel.debug, 'New client bound to scope.');
item.client = client;
} else {
_options.logger(SentryLevel.debug, 'NoOp client bound to scope.');
item.client = NoOpSentryClient();
}
} else {
_options.logger(
SentryLevel.fatal,
'Stack peek was null when bindClient',
);
}
_options.logger(SentryLevel.debug, 'New client bound to scope.');
item.client = client;
}
}

Expand Down Expand Up @@ -272,21 +221,15 @@ class Hub {
}

final item = _peek();
if (item != null) {
try {
item.client.close();
} catch (err) {
_options.logger(
SentryLevel.error,
'Error while closing the Hub.',
);
}
} else {
try {
item.client.close();
} catch (err) {
_options.logger(
SentryLevel.fatal,
'Stack peek was NULL when closing Hub',
SentryLevel.error,
'Error while closing the Hub.',
);
}

_isEnabled = false;
}
}
Expand All @@ -300,19 +243,13 @@ class Hub {
);
} else {
final item = _peek();
if (item != null) {
try {
callback(item.scope);
} catch (err) {
_options.logger(
SentryLevel.error,
"Error in the 'configureScope' callback.",
);
}
} else {

try {
callback(item.scope);
} catch (err) {
_options.logger(
SentryLevel.fatal,
'Stack peek was NULL when configureScope',
SentryLevel.error,
"Error in the 'configureScope' callback.",
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class HubAdapter implements Hub {

@override
Future<SentryId> captureMessage(
String message, {
SentryLevel level,
String template,
List params,
String? message, {
SentryLevel? level,
String? template,
List? params,
dynamic hint,
}) =>
Sentry.captureMessage(
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/isolate_error_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'sentry_options.dart';
import 'throwable_mechanism.dart';

class IsolateErrorIntegration extends Integration {
RawReceivePort _receivePort;
late RawReceivePort _receivePort;

@override
FutureOr<void> call(Hub hub, SentryOptions options) async {
Expand Down
Loading