Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
52 changes: 45 additions & 7 deletions dwds/lib/src/services/web_socket_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const _pauseIsolatesOnStartFlag = 'pause_isolates_on_start';
/// closes before the new connection is established, preventing premature isolate destruction.
const _isolateDestructionGracePeriod = Duration(seconds: 15);

/// Error message when no clients are available for hot reload.
const _noClientsForHotReload = 'No clients available for hot reload';

/// Error message when no clients are available for hot restart.
const _noClientsForHotRestart = 'No clients available for hot restart';

/// Tracks hot reload responses from multiple browser windows/tabs.
class _HotReloadTracker {
final String requestId;
Expand Down Expand Up @@ -117,6 +123,22 @@ class _ServiceExtensionTracker {
}
}

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

NoClientsAvailableException._(this.message);

factory NoClientsAvailableException.hotReload() =>
NoClientsAvailableException._(_noClientsForHotReload);

factory NoClientsAvailableException.hotRestart() =>
NoClientsAvailableException._(_noClientsForHotRestart);

@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 +526,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 kIsolateCannotReload code when no browser clients are
// connected.
throw vm_service.RPCError(
'reloadSources',
vm_service.RPCErrorKind.kIsolateCannotReload.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 +548,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 kIsolateCannotReload code when no browser clients are
// connected.
throw vm_service.RPCError(
'hotRestart',
vm_service.RPCErrorKind.kIsolateCannotReload.code,
'Hot restart failed: ${e.message}',
);
} catch (e) {
_logger.warning('Hot restart failed: $e');
return {
Expand Down Expand Up @@ -611,7 +649,8 @@ class WebSocketProxyService extends ProxyService {
});

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

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

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

// Create tracker for this hot restart request
Expand Down Expand Up @@ -737,9 +777,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 +978,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