Unverified Commit b6768ec7 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] dont let crash reporter crash tool (#66755)

package:http can throw a ClientException, which the crash reporter must catch or the tool will crash in the crash reporter. 3/4 crash on dev.
parent 0f90747b
...@@ -188,7 +188,7 @@ class CrashReportSender { ...@@ -188,7 +188,7 @@ class CrashReportSender {
// Catch all exceptions to print the message that makes clear that the // Catch all exceptions to print the message that makes clear that the
// crash logger crashed. // crash logger crashed.
} catch (sendError, sendStackTrace) { // ignore: avoid_catches_without_on_clauses } 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'); _logger.printError('Failed to send crash report due to a network error: $sendError');
} else { } else {
// If the sender itself crashes, just print. We did our best. // If the sender itself crashes, just print. We did our best.
......
...@@ -183,6 +183,25 @@ void main() { ...@@ -183,6 +183,25 @@ void main() {
expect(logger.errorText, contains('Failed to send crash report due to a network error')); 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 { testWithoutContext('should send only one crash report when sent many times', () async {
final RequestInfo requestInfo = RequestInfo(); final RequestInfo requestInfo = RequestInfo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment