[flutter_tools] wrap http send in async guard (#69972)

This commit is contained in:
Jonah Williams
2020-11-06 11:00:20 -08:00
committed by GitHub
parent 75e8428b6b
commit 1f210275aa
2 changed files with 13 additions and 9 deletions

View File

@@ -175,16 +175,19 @@ class CrashReportSender {
filename: _kStackTraceFilename,
));
final http.StreamedResponse resp = await _client.send(req);
// package:http may throw unhandled async exceptions into the Zone.
await asyncGuard(() async {
final http.StreamedResponse resp = await _client.send(req);
if (resp.statusCode == 200) {
final String reportId = await http.ByteStream(resp.stream)
.bytesToString();
_logger.printTrace('Crash report sent (report ID: $reportId)');
_crashReportSent = true;
} else {
_logger.printError('Failed to send crash report. Server responded with HTTP status code ${resp.statusCode}');
}
if (resp.statusCode == HttpStatus.ok) {
final String reportId = await http.ByteStream(resp.stream)
.bytesToString();
_logger.printTrace('Crash report sent (report ID: $reportId)');
_crashReportSent = true;
} else {
_logger.printError('Failed to send crash report. Server responded with HTTP status code ${resp.statusCode}');
}
});
// Catch all exceptions to print the message that makes clear that the
// crash logger crashed.
} catch (sendError, sendStackTrace) { // ignore: avoid_catches_without_on_clauses

View File

@@ -12,6 +12,7 @@ import 'package:intl/intl.dart';
import 'package:meta/meta.dart';
import 'package:usage/usage_io.dart';
import '../base/async_guard.dart';
import '../base/error_handling_io.dart';
import '../base/file_system.dart';
import '../base/io.dart';