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

Move async guard wrapping of crash reporter up a level (#73877)

parent da90156f
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
import 'dart:async'; import 'dart:async';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart' as intl; import 'package:intl/intl.dart' as intl;
import 'package:intl/intl_standalone.dart' as intl_standalone; import 'package:intl/intl_standalone.dart' as intl_standalone;
import 'package:http/http.dart' as http;
import 'src/base/async_guard.dart';
import 'src/base/common.dart'; import 'src/base/common.dart';
import 'src/base/context.dart'; import 'src/base/context.dart';
import 'src/base/file_system.dart'; import 'src/base/file_system.dart';
...@@ -131,19 +132,23 @@ Future<int> _handleToolError( ...@@ -131,19 +132,23 @@ Future<int> _handleToolError(
// Report to both [Usage] and [CrashReportSender]. // Report to both [Usage] and [CrashReportSender].
globals.flutterUsage.sendException(error); globals.flutterUsage.sendException(error);
final CrashReportSender crashReportSender = CrashReportSender( await asyncGuard(() async {
client: http.Client(), final CrashReportSender crashReportSender = CrashReportSender(
usage: globals.flutterUsage, client: http.Client(),
platform: globals.platform, usage: globals.flutterUsage,
logger: globals.logger, platform: globals.platform,
operatingSystemUtils: globals.os, logger: globals.logger,
); operatingSystemUtils: globals.os,
await crashReportSender.sendReport( );
error: error, await crashReportSender.sendReport(
stackTrace: stackTrace, error: error,
getFlutterVersion: getFlutterVersion, stackTrace: stackTrace,
command: args.join(' '), getFlutterVersion: getFlutterVersion,
); command: args.join(' '),
);
}, onError: (dynamic error) {
globals.printError('Error sending crash report: $error');
});
globals.printError('Oops; flutter has exited unexpectedly: "$error".'); globals.printError('Oops; flutter has exited unexpectedly: "$error".');
......
...@@ -175,19 +175,17 @@ class CrashReportSender { ...@@ -175,19 +175,17 @@ class CrashReportSender {
filename: _kStackTraceFilename, filename: _kStackTraceFilename,
)); ));
// package:http may throw unhandled async exceptions into the Zone. final http.StreamedResponse resp = await _client.send(req);
await asyncGuard(() async {
final http.StreamedResponse resp = await _client.send(req); if (resp.statusCode == HttpStatus.ok) {
final String reportId = await http.ByteStream(resp.stream)
if (resp.statusCode == HttpStatus.ok) { .bytesToString();
final String reportId = await http.ByteStream(resp.stream) _logger.printTrace('Crash report sent (report ID: $reportId)');
.bytesToString(); _crashReportSent = true;
_logger.printTrace('Crash report sent (report ID: $reportId)'); } else {
_crashReportSent = true; _logger.printError('Failed to send crash report. Server responded with HTTP status code ${resp.statusCode}');
} 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 // 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
......
...@@ -13,7 +13,6 @@ import 'package:meta/meta.dart'; ...@@ -13,7 +13,6 @@ import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import 'package:usage/usage_io.dart'; import 'package:usage/usage_io.dart';
import '../base/async_guard.dart';
import '../base/error_handling_io.dart'; import '../base/error_handling_io.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
......
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