forked from firka/flutter
Fix analysis throwing string (#91435)
This commit is contained in:
committed by
GitHub
parent
5883a6628d
commit
b0810bc939
@@ -125,7 +125,12 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
// Completing the future in the callback can't fail.
|
||||
unawaited(server.onExit.then<void>((int exitCode) {
|
||||
if (!analysisCompleter.isCompleted) {
|
||||
analysisCompleter.completeError('analysis server exited: $exitCode');
|
||||
analysisCompleter.completeError(
|
||||
// Include the last 20 lines of server output in exception message
|
||||
Exception(
|
||||
'analysis server exited with code $exitCode and output:\n${server.getLogs(20)}',
|
||||
),
|
||||
);
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class AnalysisServer {
|
||||
final Stream<String> errorStream = _process!.stderr
|
||||
.transform<String>(utf8.decoder)
|
||||
.transform<String>(const LineSplitter());
|
||||
errorStream.listen(_logger.printError);
|
||||
errorStream.listen(_handleError);
|
||||
|
||||
final Stream<String> inStream = _process!.stdout
|
||||
.transform<String>(utf8.decoder)
|
||||
@@ -94,6 +94,28 @@ class AnalysisServer {
|
||||
<String, dynamic>{'included': directories, 'excluded': <String>[]});
|
||||
}
|
||||
|
||||
final List<String> _logs = <String>[];
|
||||
|
||||
/// Aggregated STDOUT and STDERR logs from the server.
|
||||
///
|
||||
/// This can be surfaced to the user if the server crashes. If [tail] is null,
|
||||
/// returns all logs, else only the last [tail] lines.
|
||||
String getLogs([int? tail]) {
|
||||
if (tail == null) {
|
||||
return _logs.join('\n');
|
||||
}
|
||||
// Since List doesn't implement a .tail() method, we reverse it then use
|
||||
// .take()
|
||||
final Iterable<String> reversedLogs = _logs.reversed;
|
||||
final List<String> firstTailLogs = reversedLogs.take(tail).toList();
|
||||
return firstTailLogs.reversed.join('\n');
|
||||
}
|
||||
|
||||
void _handleError(String message) {
|
||||
_logs.add('[stderr] $message');
|
||||
_logger.printError(message);
|
||||
}
|
||||
|
||||
bool get didServerErrorOccur => _didServerErrorOccur;
|
||||
|
||||
Stream<bool> get onAnalyzing => _analyzingController.stream;
|
||||
@@ -113,6 +135,7 @@ class AnalysisServer {
|
||||
}
|
||||
|
||||
void _handleServerResponse(String line) {
|
||||
_logs.add('[stdout] $line');
|
||||
_logger.printTrace('<== $line');
|
||||
|
||||
final dynamic response = json.decode(line);
|
||||
|
||||
@@ -312,7 +312,6 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
||||
return <String>[];
|
||||
}
|
||||
|
||||
|
||||
final List<String> projectPaths = globals.fs.directory(rootPath)
|
||||
.listSync(followLinks: false)
|
||||
.expand((FileSystemEntity entity) {
|
||||
|
||||
Reference in New Issue
Block a user