Unverified Commit 663dc1d7 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Teach crash reporter about HttpException (#39005)

parent 0249050f
...@@ -127,7 +127,7 @@ class CrashReportSender { ...@@ -127,7 +127,7 @@ class CrashReportSender {
printError('Failed to send crash report. Server responded with HTTP status code ${resp.statusCode}'); printError('Failed to send crash report. Server responded with HTTP status code ${resp.statusCode}');
} }
} catch (sendError, sendStackTrace) { } catch (sendError, sendStackTrace) {
if (sendError is SocketException) { if (sendError is SocketException || sendError is HttpException) {
printError('Failed to send crash report due to a network error: $sendError'); 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.
......
...@@ -59,6 +59,48 @@ void main() { ...@@ -59,6 +59,48 @@ void main() {
Stdio: () => const _NoStderr(), Stdio: () => const _NoStderr(),
}); });
testUsingContext('should print an explanatory message when there is a SocketException', () async {
final Completer<int> exitCodeCompleter = Completer<int>();
setExitFunctionForTests((int exitCode) {
exitCodeCompleter.complete(exitCode);
});
CrashReportSender.initializeWith(
CrashingCrashReportSender(const SocketException('no internets')));
unawaited(tools.run(
<String>['crash'],
<FlutterCommand>[_CrashAsyncCommand()],
reportCrashes: true,
flutterVersion: 'test-version',
));
expect(await exitCodeCompleter.future, 1);
expect(testLogger.errorText, contains('Failed to send crash report due to a network error'));
}, overrides: <Type, Generator>{
Stdio: () => const _NoStderr(),
});
testUsingContext('should print an explanatory message when there is an HttpException', () async {
final Completer<int> exitCodeCompleter = Completer<int>();
setExitFunctionForTests((int exitCode) {
exitCodeCompleter.complete(exitCode);
});
CrashReportSender.initializeWith(
CrashingCrashReportSender(const HttpException('no internets')));
unawaited(tools.run(
<String>['crash'],
<FlutterCommand>[_CrashAsyncCommand()],
reportCrashes: true,
flutterVersion: 'test-version',
));
expect(await exitCodeCompleter.future, 1);
expect(testLogger.errorText, contains('Failed to send crash report due to a network error'));
}, overrides: <Type, Generator>{
Stdio: () => const _NoStderr(),
});
testUsingContext('should send crash reports when async throws', () async { testUsingContext('should send crash reports when async throws', () async {
final Completer<int> exitCodeCompleter = Completer<int>(); final Completer<int> exitCodeCompleter = Completer<int>();
setExitFunctionForTests((int exitCode) { setExitFunctionForTests((int exitCode) {
...@@ -270,6 +312,13 @@ class MockCrashReportSender extends MockClient { ...@@ -270,6 +312,13 @@ class MockCrashReportSender extends MockClient {
static int sendCalls = 0; static int sendCalls = 0;
} }
class CrashingCrashReportSender extends MockClient {
CrashingCrashReportSender(Object exception)
: super((Request request) async {
throw exception;
});
}
/// Throws a random error to simulate a CLI crash. /// Throws a random error to simulate a CLI crash.
class _CrashCommand extends FlutterCommand { class _CrashCommand extends FlutterCommand {
......
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