Commit 4c91b6e7 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Stop using package:stack_trace and Chain.capture (#8803)

- [x] Don't use package:stack_trace.
- [x] Don't use Chain.capture.
- [x] Fix an instance of aggressive catching of exceptions

Related #8742
parent a80e5c20
...@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/version.dart'; ...@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/version.dart';
import 'package:intl/intl_standalone.dart' as intl; import 'package:intl/intl_standalone.dart' as intl;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:stack_trace/stack_trace.dart';
import 'src/artifacts.dart'; import 'src/artifacts.dart';
import 'src/base/common.dart'; import 'src/base/common.dart';
...@@ -138,17 +137,14 @@ Future<int> run(List<String> args, List<FlutterCommand> subCommands, { ...@@ -138,17 +137,14 @@ Future<int> run(List<String> args, List<FlutterCommand> subCommands, {
// Initialize the system locale. // Initialize the system locale.
await intl.findSystemLocale(); await intl.findSystemLocale();
final Completer<int> runCompleter = new Completer<int>(); try {
Chain.capture<Future<Null>>(() async {
await runner.run(args); await runner.run(args);
await _exit(0); await _exit(0);
runCompleter.complete(0); } catch (error, stackTrace) {
}, onError: (dynamic error, Chain chain) {
String getVersion() => flutterVersion ?? FlutterVersion.getVersionString(); String getVersion() => flutterVersion ?? FlutterVersion.getVersionString();
_handleToolError(error, chain, verbose, args, reportCrashes, getVersion) return await _handleToolError(error, stackTrace, verbose, args, reportCrashes, getVersion);
.then(runCompleter.complete, onError: runCompleter.completeError); }
}); return 0;
return runCompleter.future;
}); });
} }
...@@ -164,7 +160,7 @@ WriteCallback writelnStderr = stderr.writeln; ...@@ -164,7 +160,7 @@ WriteCallback writelnStderr = stderr.writeln;
Future<int> _handleToolError( Future<int> _handleToolError(
dynamic error, dynamic error,
Chain chain, StackTrace stackTrace,
bool verbose, bool verbose,
List<String> args, List<String> args,
bool reportCrashes, bool reportCrashes,
...@@ -184,7 +180,7 @@ Future<int> _handleToolError( ...@@ -184,7 +180,7 @@ Future<int> _handleToolError(
writelnStderr(error.message); writelnStderr(error.message);
if (verbose) { if (verbose) {
writelnStderr(); writelnStderr();
writelnStderr(chain.terse.toString()); writelnStderr(stackTrace.toString());
writelnStderr(); writelnStderr();
} }
return _exit(error.exitCode ?? 1); return _exit(error.exitCode ?? 1);
...@@ -203,10 +199,10 @@ Future<int> _handleToolError( ...@@ -203,10 +199,10 @@ Future<int> _handleToolError(
if (!reportCrashes) { if (!reportCrashes) {
// Print the stack trace on the bots - don't write a crash report. // Print the stack trace on the bots - don't write a crash report.
writelnStderr('$error'); writelnStderr('$error');
writelnStderr(chain.terse.toString()); writelnStderr(stackTrace.toString());
return _exit(1); return _exit(1);
} else { } else {
flutterUsage.sendException(error, chain); flutterUsage.sendException(error, stackTrace);
if (error is String) if (error is String)
writelnStderr('Oops; flutter has exited unexpectedly: "$error".'); writelnStderr('Oops; flutter has exited unexpectedly: "$error".');
...@@ -215,11 +211,11 @@ Future<int> _handleToolError( ...@@ -215,11 +211,11 @@ Future<int> _handleToolError(
await CrashReportSender.instance.sendReport( await CrashReportSender.instance.sendReport(
error: error, error: error,
stackTrace: chain, stackTrace: stackTrace,
getFlutterVersion: getFlutterVersion, getFlutterVersion: getFlutterVersion,
); );
try { try {
final File file = await _createLocalCrashReport(args, error, chain); final File file = await _createLocalCrashReport(args, error, stackTrace);
writelnStderr( writelnStderr(
'Crash report written to ${file.path};\n' 'Crash report written to ${file.path};\n'
'please let us know at https://github.com/flutter/flutter/issues.', 'please let us know at https://github.com/flutter/flutter/issues.',
...@@ -249,7 +245,7 @@ Future<int> _handleToolError( ...@@ -249,7 +245,7 @@ Future<int> _handleToolError(
FileSystem crashFileSystem = const LocalFileSystem(); FileSystem crashFileSystem = const LocalFileSystem();
/// Saves the crash report to a local file. /// Saves the crash report to a local file.
Future<File> _createLocalCrashReport(List<String> args, dynamic error, Chain chain) async { Future<File> _createLocalCrashReport(List<String> args, dynamic error, StackTrace stackTrace) async {
File crashFile = getUniqueFile(crashFileSystem.currentDirectory, 'flutter', 'log'); File crashFile = getUniqueFile(crashFileSystem.currentDirectory, 'flutter', 'log');
final StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
...@@ -261,7 +257,7 @@ Future<File> _createLocalCrashReport(List<String> args, dynamic error, Chain cha ...@@ -261,7 +257,7 @@ Future<File> _createLocalCrashReport(List<String> args, dynamic error, Chain cha
buffer.writeln('## exception\n'); buffer.writeln('## exception\n');
buffer.writeln('${error.runtimeType}: $error\n'); buffer.writeln('${error.runtimeType}: $error\n');
buffer.writeln('```\n${chain.terse}```\n'); buffer.writeln('```\n$stackTrace```\n');
buffer.writeln('## flutter doctor\n'); buffer.writeln('## flutter doctor\n');
buffer.writeln('```\n${await _doctorText()}```'); buffer.writeln('```\n${await _doctorText()}```');
......
...@@ -7,7 +7,6 @@ import 'dart:convert' show ASCII, LineSplitter; ...@@ -7,7 +7,6 @@ import 'dart:convert' show ASCII, LineSplitter;
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:stack_trace/stack_trace.dart';
import 'io.dart'; import 'io.dart';
import 'platform.dart'; import 'platform.dart';
...@@ -67,7 +66,7 @@ class StdoutLogger extends Logger { ...@@ -67,7 +66,7 @@ class StdoutLogger extends Logger {
stderr.writeln(message); stderr.writeln(message);
if (stackTrace != null) if (stackTrace != null)
stderr.writeln(new Chain.forTrace(stackTrace).terse.toString()); stderr.writeln(stackTrace.toString());
} }
@override @override
...@@ -264,6 +263,7 @@ class AnsiTerminal { ...@@ -264,6 +263,7 @@ class AnsiTerminal {
static const String _reset = '\u001B[0m'; static const String _reset = '\u001B[0m';
static const String _clear = '\u001B[2J\u001B[H'; static const String _clear = '\u001B[2J\u001B[H';
static const int _ENXIO = 6;
static const int _ENOTTY = 25; static const int _ENOTTY = 25;
static const int _ENETRESET = 102; static const int _ENETRESET = 102;
static const int _ERROR_INVALID_PARAMETER = 87; static const int _ERROR_INVALID_PARAMETER = 87;
...@@ -271,6 +271,7 @@ class AnsiTerminal { ...@@ -271,6 +271,7 @@ class AnsiTerminal {
/// Setting the line mode can throw for some terminals (with "Operation not /// Setting the line mode can throw for some terminals (with "Operation not
/// supported on socket"), but the error can be safely ignored. /// supported on socket"), but the error can be safely ignored.
static const List<int> _lineModeIgnorableErrors = const <int>[ static const List<int> _lineModeIgnorableErrors = const <int>[
_ENXIO,
_ENOTTY, _ENOTTY,
_ENETRESET, _ENETRESET,
_ERROR_INVALID_PARAMETER, // TODO(goderbauer): remove when https://github.com/dart-lang/sdk/issues/28599 is fixed _ERROR_INVALID_PARAMETER, // TODO(goderbauer): remove when https://github.com/dart-lang/sdk/issues/28599 is fixed
......
...@@ -6,7 +6,6 @@ import 'dart:async'; ...@@ -6,7 +6,6 @@ import 'dart:async';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:stack_trace/stack_trace.dart';
import 'base/io.dart'; import 'base/io.dart';
import 'globals.dart'; import 'globals.dart';
...@@ -69,7 +68,7 @@ class CrashReportSender { ...@@ -69,7 +68,7 @@ class CrashReportSender {
/// The report is populated from data in [error] and [stackTrace]. /// The report is populated from data in [error] and [stackTrace].
Future<Null> sendReport({ Future<Null> sendReport({
@required dynamic error, @required dynamic error,
@required dynamic stackTrace, @required StackTrace stackTrace,
@required String getFlutterVersion(), @required String getFlutterVersion(),
}) async { }) async {
try { try {
...@@ -98,13 +97,9 @@ class CrashReportSender { ...@@ -98,13 +97,9 @@ class CrashReportSender {
req.fields['type'] = _kDartTypeId; req.fields['type'] = _kDartTypeId;
req.fields['error_runtime_type'] = '${error.runtimeType}'; req.fields['error_runtime_type'] = '${error.runtimeType}';
final Chain chain = stackTrace is StackTrace
? new Chain.forTrace(stackTrace)
: new Chain.parse(stackTrace.toString());
req.files.add(new http.MultipartFile.fromString( req.files.add(new http.MultipartFile.fromString(
_kStackTraceFileField, _kStackTraceFileField,
'${chain.terse}', stackTrace.toString(),
filename: _kStackTraceFilename, filename: _kStackTraceFilename,
)); ));
......
...@@ -5,10 +5,8 @@ ...@@ -5,10 +5,8 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:stack_trace/stack_trace.dart';
import 'application_package.dart'; import 'application_package.dart';
import 'base/common.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/utils.dart'; import 'base/utils.dart';
import 'build_info.dart'; import 'build_info.dart';
...@@ -44,30 +42,6 @@ class ColdRunner extends ResidentRunner { ...@@ -44,30 +42,6 @@ class ColdRunner extends ResidentRunner {
Completer<Null> appStartedCompleter, Completer<Null> appStartedCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) {
// Don't let uncaught errors kill the process.
return Chain.capture(() {
return _run(
traceStartup: traceStartup,
connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
route: route,
shouldBuild: shouldBuild
);
}, onError: (dynamic error, StackTrace stackTrace) {
// Actually exit on ToolExit.
if (error is ToolExit)
throw error;
printError('Exception from flutter run: $error', stackTrace);
});
}
Future<int> _run({
bool traceStartup: false,
Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<Null> appStartedCompleter,
String route,
bool shouldBuild: true
}) async { }) async {
if (!prebuiltMode) { if (!prebuiltMode) {
if (!fs.isFileSync(mainPath)) { if (!fs.isFileSync(mainPath)) {
......
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