diff --git a/pkg/dds/CHANGELOG.md b/pkg/dds/CHANGELOG.md index 3d9557a6a4c..a03ed2b861d 100644 --- a/pkg/dds/CHANGELOG.md +++ b/pkg/dds/CHANGELOG.md @@ -1,3 +1,7 @@ +# 3.1.2 +- Improved error handling for serving static DevTools assets. +- Updated `devtools_shared` constraint to ^6.0.3. + # 3.1.1 - Updated `vm_service` constraint to ^14.0.0. diff --git a/pkg/dds/README.md b/pkg/dds/README.md index 3bab225cba3..e06ceacca32 100644 --- a/pkg/dds/README.md +++ b/pkg/dds/README.md @@ -37,3 +37,26 @@ void main() { [dds-protocol]: dds_protocol.md [service-protocol]: https://github.com/dart-lang/sdk/blob/main/runtime/vm/service/service.md + +# Debugging DDS + +One way to get stdout from files in DDS while debugging is to log messages to a file. You can add a method such as: + +```dart +void _fileLog(String message) { + final file = File('/tmp/dds.log'); + if (!file.existsSync()) { + file.createSync(); + } + file.writeAsStringSync( +''' +$message +''', + mode: FileMode.append, + ); +} +``` + +Then you can call `_fileLog('some print debugging message')`, and the log message will be written to a temp file. + +To get logging output in real time, run `tail -f /tmp/dds.log`. diff --git a/pkg/dds/lib/src/devtools/handler.dart b/pkg/dds/lib/src/devtools/handler.dart index a008cf7720d..947ced3fc2a 100644 --- a/pkg/dds/lib/src/devtools/handler.dart +++ b/pkg/dds/lib/src/devtools/handler.dart @@ -71,11 +71,12 @@ FutureOr defaultHandler({ path.joinAll(pathSegments), ); final contentType = lookupMimeType(extensionAssetPath) ?? 'text/html'; + final baseHref = '$appRoot$extensionRequestPath/$extensionName/'; return _serveStaticFile( request, File(extensionAssetPath), contentType, - baseHref: '$appRoot$extensionRequestPath/$extensionName/', + baseHref: baseHref, ); } } @@ -174,12 +175,22 @@ Future _serveStaticFile( // between a static file being served and accessed. See // https://github.com/flutter/devtools/issues/6365. await Future.delayed(Duration(milliseconds: 500)); - fileBytes = file.readAsBytesSync(); + try { + fileBytes = file.readAsBytesSync(); + } catch (e) { + return Response.notFound('could not read file as bytes: ${file.path}'); + } } return Response.ok(fileBytes, headers: headers); } - var contents = file.readAsStringSync(); + late String contents; + try { + contents = file.readAsStringSync(); + } catch (e) { + return Response.notFound('could not read file as String: ${file.path}'); + } + if (baseHref != null) { assert(baseHref.startsWith('/')); assert(baseHref.endsWith('/')); diff --git a/pkg/dds/pubspec.yaml b/pkg/dds/pubspec.yaml index 6a9a7ccc3e7..0fb2b37f227 100644 --- a/pkg/dds/pubspec.yaml +++ b/pkg/dds/pubspec.yaml @@ -1,5 +1,5 @@ name: dds -version: 3.1.1 +version: 3.1.2 description: >- A library used to spawn the Dart Developer Service, used to communicate with a Dart VM Service instance.