Skip to content

Commit

Permalink
fix unawaited futures
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Jul 5, 2022
1 parent a6f3ef7 commit b5759d7
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 81 deletions.
1 change: 1 addition & 0 deletions dart/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ linter:
prefer_function_declarations_over_variables: false
no_leading_underscores_for_local_identifiers: false
avoid_renaming_method_parameters: false
unawaited_futures: true
2 changes: 1 addition & 1 deletion dart/example_web/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Future<void> runApp() async {

querySelector('#output')?.text = 'Your Dart app is running.';

Sentry.addBreadcrumb(
await Sentry.addBreadcrumb(
Breadcrumb(
message: 'Authenticated user',
category: 'auth',
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/http_client/breadcrumb_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class BreadcrumbClient extends BaseClient {
responseBodySize: responseBodySize,
);

_hub.addBreadcrumb(breadcrumb);
await _hub.addBreadcrumb(breadcrumb);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ class Hub {
}

/// Adds a breacrumb to the current Scope
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {
if (!_isEnabled) {
_options.logger(
SentryLevel.warning,
"Instance is disabled and this 'addBreadcrumb' call is a no-op.",
);
} else {
final item = _peek();
item.scope.addBreadcrumb(crumb, hint: hint);
await item.scope.addBreadcrumb(crumb, hint: hint);
}
}

Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class HubAdapter implements Hub {
}

@override
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) =>
Sentry.addBreadcrumb(crumb, hint: hint);
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async =>
await Sentry.addBreadcrumb(crumb, hint: hint);

@override
void bindClient(SentryClient client) => Sentry.bindClient(client);
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class NoOpHub implements Hub {
SentryId get lastEventId => SentryId.empty();

@override
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {}
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {}

@override
Future<SentryId> captureTransaction(SentryTransaction transaction) async =>
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ class Sentry {
static SentryId get lastEventId => _hub.lastEventId;

/// Adds a breacrumb to the current Scope
static void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) =>
_hub.addBreadcrumb(crumb, hint: hint);
static Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async =>
await _hub.addBreadcrumb(crumb, hint: hint);

/// Configures the scope through the callback.
static FutureOr<void> configureScope(ScopeCallback callback) async =>
Expand Down
4 changes: 2 additions & 2 deletions dart/test/default_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ class PrintRecursionMockHub extends MockHub {
bool get isEnabled => true;

@override
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {
print('recursion');
super.addBreadcrumb(crumb, hint: hint);
await super.addBreadcrumb(crumb, hint: hint);
}

@override
Expand Down
6 changes: 3 additions & 3 deletions dart/test/hub_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void main() {
expect(capturedEvent.event.contexts.trace, isNotNull);
});

test('Expando does not throw when exception type is not supported',
test('Expand does not throw when exception type is not supported',
() async {
final hub = fixture.getSut();

Expand Down Expand Up @@ -353,7 +353,7 @@ void main() {
..level = SentryLevel.debug
..fingerprint = ['1', '2'];

otherScope.setUser(fakeUser);
await otherScope.setUser(fakeUser);

expect(
scopeEquals(
Expand Down Expand Up @@ -388,7 +388,7 @@ void main() {
await hub.configureScope((Scope scope) {
expect(0, scope.breadcrumbs.length);
});
hub.addBreadcrumb(Breadcrumb(message: 'test'));
await hub.addBreadcrumb(Breadcrumb(message: 'test'));
await hub.configureScope((Scope scope) {
expect(1, scope.breadcrumbs.length);
expect('test', scope.breadcrumbs.first.message);
Expand Down
2 changes: 1 addition & 1 deletion dart/test/mocks/mock_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MockHub with NoSuchMethodProvider implements Hub {
}

@override
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {
addBreadcrumbCalls.add(AddBreadcrumbCall(crumb, hint));
}

Expand Down
111 changes: 56 additions & 55 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void main() {
test('clones', () async {
final sut = fixture.getSut();

sut.addBreadcrumb(Breadcrumb(
await sut.addBreadcrumb(Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
));
Expand Down Expand Up @@ -334,15 +334,15 @@ void main() {
);
final scope = Scope(SentryOptions(dsn: fakeDsn))
..fingerprint = ['example-dart']
..addBreadcrumb(breadcrumb)
..transaction = '/example/app'
..level = SentryLevel.warning
..setTag('build', '579')
..setExtra('company-name', 'Dart Inc')
..setContexts('theme', 'material')
..addEventProcessor(AddTagsEventProcessor({'page-locale': 'en-us'}));

scope.setUser(scopeUser);
await scope.addBreadcrumb(breadcrumb);
await scope.setTag('build', '579');
await scope.setExtra('company-name', 'Dart Inc');
await scope.setContexts('theme', 'material');
await scope.setUser(scopeUser);

final updatedEvent = await scope.applyToEvent(event);

Expand Down Expand Up @@ -381,10 +381,10 @@ void main() {
);
final scope = Scope(SentryOptions(dsn: fakeDsn))
..fingerprint = ['example-dart']
..addBreadcrumb(breadcrumb)
..transaction = '/example/app';

scope.setUser(scopeUser);
await scope.addBreadcrumb(breadcrumb);
await scope.setUser(scopeUser);

final updatedEvent = await scope.applyToEvent(event);

Expand All @@ -408,31 +408,31 @@ void main() {
operatingSystem: SentryOperatingSystem(name: 'event-os'),
),
);
final scope = Scope(SentryOptions(dsn: fakeDsn))
..setContexts(
SentryDevice.type,
SentryDevice(name: 'context-device'),
)
..setContexts(
SentryApp.type,
SentryApp(name: 'context-app'),
)
..setContexts(
SentryGpu.type,
SentryGpu(name: 'context-gpu'),
)
..setContexts(
SentryRuntime.listType,
[SentryRuntime(name: 'context-runtime')],
)
..setContexts(
SentryBrowser.type,
SentryBrowser(name: 'context-browser'),
)
..setContexts(
SentryOperatingSystem.type,
SentryOperatingSystem(name: 'context-os'),
);
final scope = Scope(SentryOptions(dsn: fakeDsn));
await scope.setContexts(
SentryDevice.type,
SentryDevice(name: 'context-device'),
);
await scope.setContexts(
SentryApp.type,
SentryApp(name: 'context-app'),
);
await scope.setContexts(
SentryGpu.type,
SentryGpu(name: 'context-gpu'),
);
await scope.setContexts(
SentryRuntime.listType,
[SentryRuntime(name: 'context-runtime')],
);
await scope.setContexts(
SentryBrowser.type,
SentryBrowser(name: 'context-browser'),
);
await scope.setContexts(
SentryOperatingSystem.type,
SentryOperatingSystem(name: 'context-os'),
);

final updatedEvent = await scope.applyToEvent(event);

Expand All @@ -448,19 +448,20 @@ void main() {

test('should apply the scope.contexts values ', () async {
final event = SentryEvent();
final scope = Scope(SentryOptions(dsn: fakeDsn))
..setContexts(SentryDevice.type, SentryDevice(name: 'context-device'))
..setContexts(SentryApp.type, SentryApp(name: 'context-app'))
..setContexts(SentryGpu.type, SentryGpu(name: 'context-gpu'))
..setContexts(
SentryRuntime.listType, [SentryRuntime(name: 'context-runtime')])
..setContexts(
SentryBrowser.type, SentryBrowser(name: 'context-browser'))
..setContexts(SentryOperatingSystem.type,
SentryOperatingSystem(name: 'context-os'))
..setContexts('theme', 'material')
..setContexts('version', 9)
..setContexts('location', {'city': 'London'});
final scope = Scope(SentryOptions(dsn: fakeDsn));
await scope.setContexts(
SentryDevice.type, SentryDevice(name: 'context-device'));
await scope.setContexts(SentryApp.type, SentryApp(name: 'context-app'));
await scope.setContexts(SentryGpu.type, SentryGpu(name: 'context-gpu'));
await scope.setContexts(
SentryRuntime.listType, [SentryRuntime(name: 'context-runtime')]);
await scope.setContexts(
SentryBrowser.type, SentryBrowser(name: 'context-browser'));
await scope.setContexts(SentryOperatingSystem.type,
SentryOperatingSystem(name: 'context-os'));
await scope.setContexts('theme', 'material');
await scope.setContexts('version', 9);
await scope.setContexts('location', {'city': 'London'});

final updatedEvent = await scope.applyToEvent(event);

Expand Down Expand Up @@ -524,63 +525,63 @@ void main() {

test('addBreadcrumb should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.addBreadcrumb(Breadcrumb());
await sut.addBreadcrumb(Breadcrumb());

expect(true, fixture.mockScopeObserver.calledAddBreadcrumb);
});

test('clearBreadcrumbs should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.clearBreadcrumbs();
await sut.clearBreadcrumbs();

expect(true, fixture.mockScopeObserver.calledClearBreadcrumbs);
});

test('removeContexts should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.removeContexts('fixture-key');
await sut.removeContexts('fixture-key');

expect(true, fixture.mockScopeObserver.calledRemoveContexts);
});

test('removeExtra should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.removeExtra('fixture-key');
await sut.removeExtra('fixture-key');

expect(true, fixture.mockScopeObserver.calledRemoveExtra);
});

test('removeTag should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.removeTag('fixture-key');
await sut.removeTag('fixture-key');

expect(true, fixture.mockScopeObserver.calledRemoveTag);
});

test('setContexts should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.setContexts('fixture-key', 'fixture-value');
await sut.setContexts('fixture-key', 'fixture-value');

expect(true, fixture.mockScopeObserver.calledSetContexts);
});

test('setExtra should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.setExtra('fixture-key', 'fixture-value');
await sut.setExtra('fixture-key', 'fixture-value');

expect(true, fixture.mockScopeObserver.calledSetExtra);
});

test('setTag should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.setTag('fixture-key', 'fixture-value');
await sut.setTag('fixture-key', 'fixture-value');

expect(true, fixture.mockScopeObserver.calledSetTag);
});

test('setUser should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
sut.setUser(null);
await sut.setUser(null);

expect(true, fixture.mockScopeObserver.calledSetUser);
});
Expand Down
4 changes: 2 additions & 2 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void main() {
final client = fixture.getSut(sendDefaultPii: true);
final scope = createScope(fixture.options);

scope.setUser(SentryUser(id: '987'));
await scope.setUser(SentryUser(id: '987'));

var eventWithUser = event.copyWith(
user: SentryUser(id: '123', username: 'foo bar'),
Expand All @@ -610,7 +610,7 @@ void main() {
final client = fixture.getSut(sendDefaultPii: true);
final scope = createScope(fixture.options);

scope.setUser(
await scope.setUser(
SentryUser(
id: 'id',
extras: {
Expand Down
4 changes: 2 additions & 2 deletions dart/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void runTest({Codec<List<int>, List<int>?>? gzip, bool isWeb = false}) {
);

final scope = Scope(options);
scope.setUser(clientUser);
await scope.setUser(clientUser);

await client.captureEvent(
eventWithoutContext,
Expand All @@ -418,7 +418,7 @@ void runTest({Codec<List<int>, List<int>?>? gzip, bool isWeb = false}) {
expect(loggedUserId, clientUser.id);

final secondScope = Scope(options);
secondScope.setUser(clientUser);
await secondScope.setUser(clientUser);

await client.captureEvent(
eventWithContext,
Expand Down
2 changes: 1 addition & 1 deletion dio/lib/src/breadcrumb_client_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class BreadcrumbClientAdapter extends HttpClientAdapter {
responseBodySize: responseBodySize,
);

_hub.addBreadcrumb(breadcrumb);
await _hub.addBreadcrumb(breadcrumb);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dio/test/mocks/mock_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MockHub with NoSuchMethodProvider implements Hub {
}

@override
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {
addBreadcrumbCalls.add(AddBreadcrumbCall(crumb, hint));
}

Expand Down
1 change: 1 addition & 0 deletions flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ linter:
library_private_types_in_public_api: false
no_leading_underscores_for_local_identifiers: false
prefer_function_declarations_over_variables: false
unawaited_futures: true
Loading

0 comments on commit b5759d7

Please sign in to comment.