mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Improve error handling for serving static DevTools assets.
Change-Id: I2b62461a64ef6aa8b544b4ace894d7b5ded0912e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343000 Reviewed-by: Derek Xu <derekx@google.com> Commit-Queue: Kenzie Davisson <kenzieschmoll@google.com>
This commit is contained in:
parent
3618845695
commit
c680feedaf
|
@ -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.
|
||||
|
||||
|
|
|
@ -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`.
|
||||
|
|
|
@ -71,11 +71,12 @@ FutureOr<Handler> 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<Response> _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('/'));
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue