forked from firka/flutter
[flutter tools] Move _informUserOfCrash into crash_reporting.dart (#55614)
This commit is contained in:
@@ -160,7 +160,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
|
||||
diagnostics?.add(
|
||||
'Unexpected failure parsing device information from adb output:\n'
|
||||
'$line\n'
|
||||
'Please report a bug at https://github.com/flutter/flutter/issues/new/choose');
|
||||
'${globals.userMessages.flutterToolBugInstructions}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ UserMessages get userMessages => context.get<UserMessages>();
|
||||
|
||||
/// Class containing message strings that can be produced by Flutter tools.
|
||||
class UserMessages {
|
||||
// Messages used in multiple components.
|
||||
String get flutterToolBugInstructions =>
|
||||
'Please report a bug at https://github.com/flutter/flutter/issues.';
|
||||
|
||||
// Messages used in FlutterValidator
|
||||
String flutterStatusInfo(String channel, String version, String os, String locale) =>
|
||||
'Channel ${channel ?? 'unknown'}, ${version ?? 'Unknown'}, on $os, locale $locale';
|
||||
|
||||
@@ -116,6 +116,12 @@ Future<T> runInContext<T>(
|
||||
logger: globals.logger,
|
||||
platform: globals.platform,
|
||||
),
|
||||
CrashReporter: () => CrashReporter(
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
flutterProjectFactory: globals.projectFactory,
|
||||
client: globals.httpClientFactory?.call() ?? HttpClient(),
|
||||
),
|
||||
DevFSConfig: () => DevFSConfig(),
|
||||
DeviceManager: () => DeviceManager(),
|
||||
Doctor: () => Doctor(logger: globals.logger),
|
||||
|
||||
@@ -39,7 +39,9 @@ Artifacts get artifacts => context.get<Artifacts>();
|
||||
BuildSystem get buildSystem => context.get<BuildSystem>();
|
||||
Cache get cache => context.get<Cache>();
|
||||
Config get config => context.get<Config>();
|
||||
CrashReporter get crashReporter => context.get<CrashReporter>();
|
||||
Doctor get doctor => context.get<Doctor>();
|
||||
HttpClientFactory get httpClientFactory => context.get<HttpClientFactory>();
|
||||
Logger get logger => context.get<Logger>();
|
||||
OperatingSystemUtils get os => context.get<OperatingSystemUtils>();
|
||||
PersistentToolState get persistentToolState => PersistentToolState.instance;
|
||||
|
||||
@@ -26,15 +26,73 @@ const String _kStackTraceFileField = 'DartError';
|
||||
/// it must be supplied in the request.
|
||||
const String _kStackTraceFilename = 'stacktrace_file';
|
||||
|
||||
class CrashDetails {
|
||||
CrashDetails({
|
||||
@required this.command,
|
||||
@required this.error,
|
||||
@required this.stackTrace,
|
||||
@required this.doctorText,
|
||||
});
|
||||
|
||||
final String command;
|
||||
final dynamic error;
|
||||
final StackTrace stackTrace;
|
||||
final String doctorText;
|
||||
}
|
||||
|
||||
/// Reports information about the crash to the user.
|
||||
class CrashReporter {
|
||||
CrashReporter({
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
@required FlutterProjectFactory flutterProjectFactory,
|
||||
@required HttpClient client,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_logger = logger,
|
||||
_flutterProjectFactory = flutterProjectFactory,
|
||||
_client = client;
|
||||
|
||||
final FileSystem _fileSystem;
|
||||
final Logger _logger;
|
||||
final FlutterProjectFactory _flutterProjectFactory;
|
||||
final HttpClient _client;
|
||||
|
||||
/// Prints instructions for filing a bug about the crash.
|
||||
Future<void> informUser(CrashDetails details, File crashFile) async {
|
||||
_logger.printError('A crash report has been written to ${crashFile.path}.');
|
||||
_logger.printStatus('This crash may already be reported. Check GitHub for similar crashes.', emphasis: true);
|
||||
|
||||
final String similarIssuesURL = GitHubTemplateCreator.toolCrashSimilarIssuesURL(details.error.toString());
|
||||
_logger.printStatus('$similarIssuesURL\n', wrap: false);
|
||||
_logger.printStatus('To report your crash to the Flutter team, first read the guide to filing a bug.', emphasis: true);
|
||||
_logger.printStatus('https://flutter.dev/docs/resources/bug-reports\n', wrap: false);
|
||||
|
||||
_logger.printStatus('Create a new GitHub issue by pasting this link into your browser and completing the issue template. Thank you!', emphasis: true);
|
||||
|
||||
final GitHubTemplateCreator gitHubTemplateCreator = GitHubTemplateCreator(
|
||||
fileSystem: _fileSystem,
|
||||
logger: _logger,
|
||||
flutterProjectFactory: _flutterProjectFactory,
|
||||
client: _client,
|
||||
);
|
||||
|
||||
final String gitHubTemplateURL = await gitHubTemplateCreator.toolCrashIssueTemplateGitHubURL(
|
||||
details.command,
|
||||
details.error,
|
||||
details.stackTrace,
|
||||
details.doctorText,
|
||||
);
|
||||
_logger.printStatus('$gitHubTemplateURL\n', wrap: false);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends crash reports to Google.
|
||||
///
|
||||
/// There are two ways to override the behavior of this class:
|
||||
///
|
||||
/// * Define a `FLUTTER_CRASH_SERVER_BASE_URL` environment variable that points
|
||||
/// to a custom crash reporting server. This is useful if your development
|
||||
/// environment is behind a firewall and unable to send crash reports to
|
||||
/// Google, or when you wish to use your own server for collecting crash
|
||||
/// reports from Flutter Tools.
|
||||
/// To override the behavior of this class, define a
|
||||
/// `FLUTTER_CRASH_SERVER_BASE_URL` environment variable that points to a custom
|
||||
/// crash reporting server. This is useful if your development environment is
|
||||
/// behind a firewall and unable to send crash reports to Google, or when you
|
||||
/// wish to use your own server for collecting crash reports from Flutter Tools.
|
||||
class CrashReportSender {
|
||||
CrashReportSender({
|
||||
@required http.Client client,
|
||||
|
||||
Reference in New Issue
Block a user