Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 26.1.0-wip
## 26.1.0

- `reloadSources` and `hotRestart` now throw an RPC error with `kServerError` code when `NoClientsAvailableException` is caught (no browser clients are connected), allowing tooling to detect and handle this scenario.
- `pause` now does not send a `PauseInterrupted` event in
`WebSocketProxyService` as we didn't actually pause.

Expand Down
40 changes: 33 additions & 7 deletions dwds/lib/src/services/web_socket_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ class _ServiceExtensionTracker {
}
}

/// Exception thrown when no browser clients are connected to DWDS.
class NoClientsAvailableException implements Exception {
final String message;

NoClientsAvailableException(this.message);

@override
String toString() => 'NoClientsAvailableException: $message';
}

/// WebSocket-based VM service proxy for web debugging.
class WebSocketProxyService extends ProxyService {
final _logger = Logger('WebSocketProxyService');
Expand Down Expand Up @@ -504,6 +514,14 @@ class WebSocketProxyService extends ProxyService {
await _performWebSocketHotReload();
_logger.info('Hot reload completed successfully');
return _ReloadReportWithMetadata(success: true);
} on NoClientsAvailableException catch (e) {
// Throw RPC error with kServerError code when no browser clients are
// connected.
throw vm_service.RPCError(
'reloadSources',
vm_service.RPCErrorKind.kServerError.code,
'Hot reload failed: ${e.message}',
);
} catch (e) {
_logger.warning('Hot reload failed: $e');
return _ReloadReportWithMetadata(success: false, notices: [e.toString()]);
Expand All @@ -518,6 +536,14 @@ class WebSocketProxyService extends ProxyService {
await _performWebSocketHotRestart();
_logger.info('Hot restart completed successfully');
return {'result': vm_service.Success().toJson()};
} on NoClientsAvailableException catch (e) {
// Throw RPC error with kServerError code when no browser clients are
// connected.
throw vm_service.RPCError(
'hotRestart',
vm_service.RPCErrorKind.kServerError.code,
'Hot restart failed: ${e.message}',
);
} catch (e) {
_logger.warning('Hot restart failed: $e');
return {
Expand Down Expand Up @@ -611,7 +637,8 @@ class WebSocketProxyService extends ProxyService {
});

if (clientCount == 0) {
throw StateError('No clients available for hot reload');
_logger.warning('No clients available for hot reload');
throw NoClientsAvailableException('No clients available for hot reload');
}

// Create tracker for this hot reload request
Expand Down Expand Up @@ -671,7 +698,8 @@ class WebSocketProxyService extends ProxyService {
});

if (clientCount == 0) {
throw StateError('No clients available for hot restart');
_logger.warning('No clients available for hot restart');
throw NoClientsAvailableException('No clients available for hot restart');
}

// Create tracker for this hot restart request
Expand Down Expand Up @@ -737,9 +765,7 @@ class WebSocketProxyService extends ProxyService {
final request = ServiceExtensionRequest.fromArgs(
id: requestId,
method: method,
args: args != null
? Map<String, dynamic>.from(args)
: <String, dynamic>{},
args: <String, Object?>{...?args},
);

// Send the request and get the number of connected clients
Expand Down Expand Up @@ -940,8 +966,8 @@ class WebSocketProxyService extends ProxyService {
/// Pauses execution of the isolate.
@override
Future<Success> pause(String isolateId) =>
// Can't pause with the web socket implementation, so do nothing.
Future.value(Success());
// Can't pause with the web socket implementation, so do nothing.
Future.value(Success());

/// Resumes execution of the isolate.
@override
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dwds
# Every time this changes you need to run `dart run build_runner build`.
version: 26.1.0-wip
version: 26.1.0

description: >-
A service that proxies between the Chrome debug protocol and the Dart VM
Expand Down
Loading