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