create a crash report
This commit is contained in:
@@ -6,6 +6,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'src/base/context.dart';
|
||||
@@ -31,6 +32,7 @@ import 'src/commands/update_packages.dart';
|
||||
import 'src/commands/upgrade.dart';
|
||||
import 'src/device.dart';
|
||||
import 'src/doctor.dart';
|
||||
import 'src/globals.dart';
|
||||
import 'src/runner/flutter_command_runner.dart';
|
||||
|
||||
/// Main entry point for commands.
|
||||
@@ -89,9 +91,65 @@ Future<Null> main(List<String> args) async {
|
||||
// We've caught an exit code.
|
||||
exit(error.exitCode);
|
||||
} else {
|
||||
stderr.writeln(error);
|
||||
stderr.writeln(chain.terse);
|
||||
// We've crashed; emit a log report.
|
||||
stderr.writeln();
|
||||
stderr.writeln('Oops; flutter has crashed: "$error"');
|
||||
|
||||
File file = _createCrashReport(args, error, chain);
|
||||
|
||||
stderr.writeln();
|
||||
stderr.writeln('Crash report written to ${path.relative(file.path)}.');
|
||||
stderr.writeln('Please let us know at https://github.com/flutter/flutter/issues!');
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
File _createCrashReport(List<String> args, dynamic error, Chain chain) {
|
||||
File crashFile = _createCrashFileName(Directory.current, 'flutter');
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
buf.writeln('Flutter crash report; please file at https://github.com/flutter/flutter/issues.\n');
|
||||
|
||||
buf.writeln('## command\n');
|
||||
buf.writeln('flutter ${args.join(' ')}\n');
|
||||
|
||||
buf.writeln('## exception\n');
|
||||
buf.writeln('$error\n');
|
||||
buf.writeln('${chain.terse}');
|
||||
|
||||
buf.writeln('## flutter doctor\n');
|
||||
buf.writeln(_doctorText());
|
||||
|
||||
crashFile.writeAsStringSync(buf.toString());
|
||||
|
||||
return crashFile;
|
||||
}
|
||||
|
||||
File _createCrashFileName(Directory dir, String baseName) {
|
||||
int i = 1;
|
||||
|
||||
while (true) {
|
||||
String name = '${baseName}_${i.toString().padLeft(2, '0')}.log';
|
||||
File file = new File(path.join(dir.path, name));
|
||||
if (!file.existsSync())
|
||||
return file;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
String _doctorText() {
|
||||
try {
|
||||
BufferLogger logger = new BufferLogger();
|
||||
AppContext appContext = new AppContext();
|
||||
|
||||
appContext[Logger] = logger;
|
||||
|
||||
appContext.runInZone(() => doctor.diagnose());
|
||||
|
||||
return logger.statusText;
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user