Skip to content

Catch exceptions in unawaited Futures #1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions dwds/lib/shared/batched_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';
import 'package:async/async.dart';
import 'package:dwds/src/utilities/shared.dart';

/// Stream controller allowing to batch events.
class BatchedStreamController<T> {
Expand All @@ -28,7 +29,7 @@ class BatchedStreamController<T> {
_inputController = StreamController<T>(),
_outputController = StreamController<List<T>>() {
_inputQueue = StreamQueue<T>(_inputController.stream);
unawaited(_batchAndSendEvents());
safeUnawaited(_batchAndSendEvents());
}

/// Sink collecting events.
Expand All @@ -39,7 +40,7 @@ class BatchedStreamController<T> {

/// Close the controller.
Future<dynamic> close() async {
unawaited(_inputController.close());
safeUnawaited(_inputController.close());
return _completer.future.then((value) => _outputController.close());
}

Expand Down
3 changes: 2 additions & 1 deletion dwds/lib/src/connections/app_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:dwds/data/connect_request.dart';
import 'package:dwds/data/run_request.dart';
import 'package:dwds/data/serializers.dart';
import 'package:dwds/src/handlers/socket_connections.dart';
import 'package:dwds/src/utilities/shared.dart';

/// A connection between the application loaded in the browser and DWDS.
class AppConnection {
Expand All @@ -19,7 +20,7 @@ class AppConnection {
final SocketConnection _connection;

AppConnection(this.request, this._connection) {
unawaited(_connection.sink.done.then((v) => _doneCompleter.complete()));
safeUnawaited(_connection.sink.done.then((v) => _doneCompleter.complete()));
}

bool get isInKeepAlivePeriod => _connection.isInKeepAlivePeriod;
Expand Down
1 change: 1 addition & 0 deletions dwds/lib/src/debugging/debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:dwds/src/utilities/conversions.dart';
import 'package:dwds/src/utilities/dart_uri.dart';
import 'package:dwds/src/utilities/domain.dart';
import 'package:dwds/src/utilities/objects.dart' show Property;
import 'package:dwds/src/utilities/server.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:dwds/src/utilities/synchronized.dart';
import 'package:logging/logging.dart';
Expand Down
1 change: 1 addition & 0 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:dwds/src/readers/asset_reader.dart';
import 'package:dwds/src/utilities/conversions.dart';
import 'package:dwds/src/utilities/dart_uri.dart';
import 'package:dwds/src/utilities/domain.dart';
import 'package:dwds/src/utilities/server.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:logging/logging.dart';
import 'package:vm_service/vm_service.dart';
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/metadata/function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'package:dwds/src/debugging/remote_debugger.dart';
import 'package:dwds/src/loaders/strategy.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:dwds/src/utilities/server.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

/// Meta data for a remote Dart function in Chrome.
Expand Down
12 changes: 7 additions & 5 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import 'package:dwds/src/servers/extension_backend.dart';
import 'package:dwds/src/services/app_debug_services.dart';
import 'package:dwds/src/services/debug_service.dart';
import 'package:dwds/src/services/expression_compiler.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
import 'package:sse/server/sse_handler.dart';
Expand Down Expand Up @@ -159,7 +160,7 @@ class DevHandler {
.takeUntilGap(const Duration(milliseconds: 50));
// We enqueue this work as we need to begin listening (`.hasNext`)
// before events are received.
unawaited(Future.microtask(() => connection.runtime.enable()));
safeUnawaited(Future.microtask(() => connection.runtime.enable()));

await for (var contextId in contextIds) {
final result = await connection.sendCommand('Runtime.evaluate', {
Expand All @@ -175,7 +176,7 @@ class DevHandler {
}
}
if (appTab != null) break;
unawaited(connection.close());
safeUnawaited(connection.close());
}
if (appTab == null || tabConnection == null || executionContext == null) {
throw AppConnectionException(
Expand Down Expand Up @@ -234,7 +235,7 @@ class DevHandler {
await _chromeConnection(), appConnection);
appServices = await _createAppDebugServices(
appConnection.request.appId, debugService);
unawaited(appServices.chromeProxyService.remoteDebugger.onClose.first
safeUnawaited(appServices.chromeProxyService.remoteDebugger.onClose.first
.whenComplete(() async {
await appServices?.close();
_servicesByAppId.remove(appConnection.request.appId);
Expand Down Expand Up @@ -301,7 +302,7 @@ class DevHandler {
}
});

unawaited(injectedConnection.sink.done.then((_) async {
safeUnawaited(injectedConnection.sink.done.then((_) async {
_injectedConnections.remove(injectedConnection);
final connection = appConnection;
if (connection != null) {
Expand Down Expand Up @@ -533,7 +534,8 @@ class DevHandler {
);
final encodedUri = await debugService.encodedUri;
extensionDebugger.sendEvent('dwds.encodedUri', encodedUri);
unawaited(appServices.chromeProxyService.remoteDebugger.onClose.first
safeUnawaited(appServices
.chromeProxyService.remoteDebugger.onClose.first
.whenComplete(() async {
appServices?.chromeProxyService.destroyIsolate();
await appServices?.close();
Expand Down
Loading