diff --git a/packages/flutter_tools/lib/src/reporting/crash_reporting.dart b/packages/flutter_tools/lib/src/reporting/crash_reporting.dart index 6af8402f0e..f365b76517 100644 --- a/packages/flutter_tools/lib/src/reporting/crash_reporting.dart +++ b/packages/flutter_tools/lib/src/reporting/crash_reporting.dart @@ -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 diff --git a/packages/flutter_tools/lib/src/reporting/reporting.dart b/packages/flutter_tools/lib/src/reporting/reporting.dart index d92a520c5a..859f1121ab 100644 --- a/packages/flutter_tools/lib/src/reporting/reporting.dart +++ b/packages/flutter_tools/lib/src/reporting/reporting.dart @@ -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';