Skip to content

handle failing to listen to vm service streams during startup #124

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 2 commits into from
May 12, 2025
Merged
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
30 changes: 24 additions & 6 deletions pkgs/dart_tooling_mcp_server/lib/src/mixins/dtd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ base mixin DartToolingDaemonSupport
vmServiceUri,
));
// Start listening for and collecting errors immediately.
final errorService = await _AppErrorsListener.forVmService(vmService);
final errorService = await _AppErrorsListener.forVmService(
vmService,
this,
);
final resource = Resource(
uri: '$runtimeErrorsScheme://${debugSession.id}',
name: debugSession.name,
Expand Down Expand Up @@ -287,7 +290,10 @@ base mixin DartToolingDaemonSupport
return _callOnVmService(
callback: (vmService) async {
if (request.arguments?['clearRuntimeErrors'] == true) {
(await _AppErrorsListener.forVmService(vmService)).errors.clear();
(await _AppErrorsListener.forVmService(
vmService,
this,
)).errors.clear();
}

StreamSubscription<Event>? serviceStreamSubscription;
Expand Down Expand Up @@ -365,7 +371,10 @@ base mixin DartToolingDaemonSupport
return _callOnVmService(
callback: (vmService) async {
try {
final errorService = await _AppErrorsListener.forVmService(vmService);
final errorService = await _AppErrorsListener.forVmService(
vmService,
this,
);
final errors = errorService.errors;

if (errors.isEmpty) {
Expand Down Expand Up @@ -794,7 +803,10 @@ class _AppErrorsListener {

/// Returns the canonical [_AppErrorsListener] for the [vmService] instance,
/// which may be an already existing instance.
static Future<_AppErrorsListener> forVmService(VmService vmService) async {
static Future<_AppErrorsListener> forVmService(
VmService vmService,
LoggingSupport logger,
) async {
return _errorListeners[vmService] ??= await () async {
// Needs to be a broadcast stream because we use it to add errors to the
// list but also expose it to clients so they can know when new errors
Expand Down Expand Up @@ -824,8 +836,14 @@ class _AppErrorsListener {
errorsController.add(message);
});

await vmService.streamListen(EventStreams.kExtension);
await vmService.streamListen(EventStreams.kStderr);
try {
await [
vmService.streamListen(EventStreams.kExtension),
vmService.streamListen(EventStreams.kStderr),
].wait;
} on RPCError catch (e) {
logger.log(LoggingLevel.error, 'Error subscribing app errors: $e');
}
return _AppErrorsListener._(
errors,
errorsController,
Expand Down