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

This commit is contained in:
Zachary Anderson
2019-08-22 09:18:25 -07:00
committed by GitHub
parent 0249050f23
commit 663dc1d774
2 changed files with 50 additions and 1 deletions

View File

@@ -127,7 +127,7 @@ class CrashReportSender {
printError('Failed to send crash report. Server responded with HTTP status code ${resp.statusCode}');
}
} 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');
} else {
// If the sender itself crashes, just print. We did our best.

View File

@@ -59,6 +59,48 @@ void main() {
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 {
final Completer<int> exitCodeCompleter = Completer<int>();
setExitFunctionForTests((int exitCode) {
@@ -270,6 +312,13 @@ class MockCrashReportSender extends MockClient {
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.
class _CrashCommand extends FlutterCommand {