diff --git a/packages/flutter_tools/lib/src/reporting/crash_reporting.dart b/packages/flutter_tools/lib/src/reporting/crash_reporting.dart index e322006664..6af8402f0e 100644 --- a/packages/flutter_tools/lib/src/reporting/crash_reporting.dart +++ b/packages/flutter_tools/lib/src/reporting/crash_reporting.dart @@ -188,7 +188,7 @@ class CrashReportSender { // Catch all exceptions to print the message that makes clear that the // crash logger crashed. } catch (sendError, sendStackTrace) { // ignore: avoid_catches_without_on_clauses - if (sendError is SocketException || sendError is HttpException) { + if (sendError is SocketException || sendError is HttpException || sendError is http.ClientException) { _logger.printError('Failed to send crash report due to a network error: $sendError'); } else { // If the sender itself crashes, just print. We did our best. diff --git a/packages/flutter_tools/test/general.shard/crash_reporting_test.dart b/packages/flutter_tools/test/general.shard/crash_reporting_test.dart index 585030a1be..b0dad606fa 100644 --- a/packages/flutter_tools/test/general.shard/crash_reporting_test.dart +++ b/packages/flutter_tools/test/general.shard/crash_reporting_test.dart @@ -183,6 +183,25 @@ void main() { expect(logger.errorText, contains('Failed to send crash report due to a network error')); }); + testWithoutContext('should print an explanatory message when there is a ClientException', () async { + final CrashReportSender crashReportSender = CrashReportSender( + client: CrashingCrashReportSender(const HttpException('no internets')), + usage: mockUsage, + platform: platform, + logger: logger, + operatingSystemUtils: operatingSystemUtils, + ); + + await crashReportSender.sendReport( + error: ClientException('Test bad state error'), + stackTrace: null, + getFlutterVersion: () => 'test-version', + command: 'crash', + ); + + expect(logger.errorText, contains('Failed to send crash report due to a network error')); + }); + testWithoutContext('should send only one crash report when sent many times', () async { final RequestInfo requestInfo = RequestInfo();