Skip to content

Add type check for responses from expression compiler worker #1696

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
Show file tree
Hide file tree
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
37 changes: 24 additions & 13 deletions dwds/lib/src/services/expression_compiler_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ class _Compiler {

/// Sends [request] on [_sendPort] and returns the next event from the
/// response stream.
Future<Map<String, Object>> _send(Map<String, Object> request) async {
Future<Map<String, dynamic>> _send(Map<String, Object> request) async {
_sendPort.send(request);
return await _responseQueue.hasNext
? Map<String, Object>.from(await _responseQueue.next)
: {
'succeeded': false,
'errors': ['compilation service response stream closed'],
};
if (!await _responseQueue.hasNext) {
return {
'succeeded': false,
'errors': ['compilation worker response stream closed'],
};
}
final response = await _responseQueue.next;
if (response is! Map<String, dynamic>) {
return {
'succeeded': false,
'errors': ['compilation worker returned invalid response: $response'],
};
}
return response;
}

/// Starts expression compilation service.
Expand All @@ -46,11 +54,11 @@ class _Compiler {
/// expression compilation (summaries, libraries spec, compiler worker
/// snapshot).
///
/// [soundNullSafety] indiciates if the compioler should support sound null
/// safety.
/// [soundNullSafety] indicates if the compiler should support sound
/// null safety.
///
/// Performs handshake with the isolate running expression compiler
/// worker to estabish communication via send/receive ports, returns
/// worker to establish communication via send/receive ports, returns
/// the service after the communication is established.
///
/// Users need to stop the service by calling [stop].
Expand Down Expand Up @@ -131,9 +139,12 @@ class _Compiler {
if (result) {
_logger.info('Updated dependencies.');
} else {
final e = response['exception'];
final s = response['stackTrace'];
_logger.severe('Failed to update dependencies: $e:$s');
final errors = response['errors'];
final exception = response['exception'];
final s = response['stackTrace'] as String?;
final stackTrace = s == null ? null : StackTrace.fromString(s);
_logger.severe(
'Failed to update dependencies: $errors', exception, stackTrace);
}
updateCompleter.complete();
return result;
Expand Down
8 changes: 5 additions & 3 deletions dwds/test/expression_compiler_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ void main() async {
output.stream.listen(printOnFailure);

configureLogWriter(
customLogWriter: (level, message, {error, loggerName, stackTrace}) =>
output.add('[$level] $loggerName: $message'));
customLogWriter: (level, message, {error, loggerName, stackTrace}) {
final e = error == null ? '' : ': $error';
final s = stackTrace == null ? '' : ':\n$stackTrace';
output.add('[$level] $loggerName: $message$e$s');
});

// start asset server
_server = await startHttpServer('localhost');
Expand Down Expand Up @@ -147,7 +150,6 @@ void main() async {
'[FINEST] ExpressionCompilerService: Compiled "true" to:')));
expect(output.stream,
emitsThrough(contains('[INFO] ExpressionCompilerService: Stopped.')));

final result = await service
.updateDependencies({'try': ModuleInfo('try.full.dill', 'try.dill')});
expect(result, true, reason: 'failed to update dependencies');
Expand Down