Skip to content

Commit c25ff11

Browse files
author
Anna Gringauze
authored
Add type check for responses from expression compiler worker (#1696)
1 parent 89fb338 commit c25ff11

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

dwds/lib/src/services/expression_compiler_service.dart

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,22 @@ class _Compiler {
2727

2828
/// Sends [request] on [_sendPort] and returns the next event from the
2929
/// response stream.
30-
Future<Map<String, Object>> _send(Map<String, Object> request) async {
30+
Future<Map<String, dynamic>> _send(Map<String, Object> request) async {
3131
_sendPort.send(request);
32-
return await _responseQueue.hasNext
33-
? Map<String, Object>.from(await _responseQueue.next)
34-
: {
35-
'succeeded': false,
36-
'errors': ['compilation service response stream closed'],
37-
};
32+
if (!await _responseQueue.hasNext) {
33+
return {
34+
'succeeded': false,
35+
'errors': ['compilation worker response stream closed'],
36+
};
37+
}
38+
final response = await _responseQueue.next;
39+
if (response is! Map<String, dynamic>) {
40+
return {
41+
'succeeded': false,
42+
'errors': ['compilation worker returned invalid response: $response'],
43+
};
44+
}
45+
return response;
3846
}
3947

4048
/// Starts expression compilation service.
@@ -46,11 +54,11 @@ class _Compiler {
4654
/// expression compilation (summaries, libraries spec, compiler worker
4755
/// snapshot).
4856
///
49-
/// [soundNullSafety] indiciates if the compioler should support sound null
50-
/// safety.
57+
/// [soundNullSafety] indicates if the compiler should support sound
58+
/// null safety.
5159
///
5260
/// Performs handshake with the isolate running expression compiler
53-
/// worker to estabish communication via send/receive ports, returns
61+
/// worker to establish communication via send/receive ports, returns
5462
/// the service after the communication is established.
5563
///
5664
/// Users need to stop the service by calling [stop].
@@ -131,9 +139,12 @@ class _Compiler {
131139
if (result) {
132140
_logger.info('Updated dependencies.');
133141
} else {
134-
final e = response['exception'];
135-
final s = response['stackTrace'];
136-
_logger.severe('Failed to update dependencies: $e:$s');
142+
final errors = response['errors'];
143+
final exception = response['exception'];
144+
final s = response['stackTrace'] as String?;
145+
final stackTrace = s == null ? null : StackTrace.fromString(s);
146+
_logger.severe(
147+
'Failed to update dependencies: $errors', exception, stackTrace);
137148
}
138149
updateCompleter.complete();
139150
return result;

dwds/test/expression_compiler_service_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ void main() async {
5555
output.stream.listen(printOnFailure);
5656

5757
configureLogWriter(
58-
customLogWriter: (level, message, {error, loggerName, stackTrace}) =>
59-
output.add('[$level] $loggerName: $message'));
58+
customLogWriter: (level, message, {error, loggerName, stackTrace}) {
59+
final e = error == null ? '' : ': $error';
60+
final s = stackTrace == null ? '' : ':\n$stackTrace';
61+
output.add('[$level] $loggerName: $message$e$s');
62+
});
6063

6164
// start asset server
6265
_server = await startHttpServer('localhost');
@@ -147,7 +150,6 @@ void main() async {
147150
'[FINEST] ExpressionCompilerService: Compiled "true" to:')));
148151
expect(output.stream,
149152
emitsThrough(contains('[INFO] ExpressionCompilerService: Stopped.')));
150-
151153
final result = await service
152154
.updateDependencies({'try': ModuleInfo('try.full.dill', 'try.dill')});
153155
expect(result, true, reason: 'failed to update dependencies');

0 commit comments

Comments
 (0)