forked from firka/flutter
Hide PII from doctor validators for GitHub template (#96250)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'android/android_studio_validator.dart';
|
||||
@@ -290,11 +291,17 @@ class Doctor {
|
||||
}
|
||||
|
||||
/// Print information about the state of installed tooling.
|
||||
///
|
||||
/// To exclude personally identifiable information like device names and
|
||||
/// paths, set [showPii] to false.
|
||||
Future<bool> diagnose({
|
||||
bool androidLicenses = false,
|
||||
bool verbose = true,
|
||||
bool showColor = true,
|
||||
AndroidLicenseValidator? androidLicenseValidator,
|
||||
bool showPii = true,
|
||||
List<ValidatorTask>? startedValidatorTasks,
|
||||
bool sendEvent = true,
|
||||
}) async {
|
||||
if (androidLicenses && androidLicenseValidator != null) {
|
||||
return androidLicenseValidator.runLicenseManager();
|
||||
@@ -306,7 +313,7 @@ class Doctor {
|
||||
bool doctorResult = true;
|
||||
int issues = 0;
|
||||
|
||||
for (final ValidatorTask validatorTask in startValidatorTasks()) {
|
||||
for (final ValidatorTask validatorTask in startedValidatorTasks ?? startValidatorTasks()) {
|
||||
final DoctorValidator validator = validatorTask.validator;
|
||||
final Status status = _logger.startSpinner();
|
||||
ValidationResult result;
|
||||
@@ -334,8 +341,9 @@ class Doctor {
|
||||
case ValidationType.installed:
|
||||
break;
|
||||
}
|
||||
|
||||
DoctorResultEvent(validator: validator, result: result).send();
|
||||
if (sendEvent) {
|
||||
DoctorResultEvent(validator: validator, result: result).send();
|
||||
}
|
||||
|
||||
final String leadingBox = showColor ? result.coloredLeadingBox : result.leadingBox;
|
||||
if (result.statusInfo != null) {
|
||||
@@ -351,7 +359,7 @@ class Doctor {
|
||||
int hangingIndent = 2;
|
||||
int indent = 4;
|
||||
final String indicator = showColor ? message.coloredIndicator : message.indicator;
|
||||
for (final String line in '$indicator ${message.message}'.split('\n')) {
|
||||
for (final String line in '$indicator ${showPii ? message.message : message.piiStrippedMessage}'.split('\n')) {
|
||||
_logger.printStatus(line, hangingIndent: hangingIndent, indent: indent, emphasis: true);
|
||||
// Only do hanging indent for the first line.
|
||||
hangingIndent = 0;
|
||||
@@ -558,3 +566,34 @@ class DeviceValidator extends DoctorValidator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper for doctor to run multiple times with PII and without, running the validators only once.
|
||||
class DoctorText {
|
||||
DoctorText(
|
||||
BufferLogger logger, {
|
||||
@visibleForTesting Doctor? doctor,
|
||||
}) : _doctor = doctor ?? Doctor(logger: logger), _logger = logger;
|
||||
|
||||
final BufferLogger _logger;
|
||||
final Doctor _doctor;
|
||||
bool _sendDoctorEvent = true;
|
||||
|
||||
late final Future<String> text = _runDiagnosis(true);
|
||||
late final Future<String> piiStrippedText = _runDiagnosis(false);
|
||||
|
||||
// Start the validator tasks only once.
|
||||
late final List<ValidatorTask> _validatorTasks = _doctor.startValidatorTasks();
|
||||
|
||||
Future<String> _runDiagnosis(bool showPii) async {
|
||||
try {
|
||||
await _doctor.diagnose(showColor: false, startedValidatorTasks: _validatorTasks, showPii: showPii, sendEvent: _sendDoctorEvent);
|
||||
// Do not send the doctor event a second time.
|
||||
_sendDoctorEvent = false;
|
||||
final String text = _logger.statusText;
|
||||
_logger.clear();
|
||||
return text;
|
||||
} on Exception catch (error, trace) {
|
||||
return 'encountered exception: $error\n\n${trace.toString().trim()}\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,22 +221,27 @@ class ValidationMessage {
|
||||
///
|
||||
/// The [contextUrl] may be supplied to link to external resources. This
|
||||
/// is displayed after the informative message in verbose modes.
|
||||
const ValidationMessage(this.message, {this.contextUrl}) : type = ValidationMessageType.information;
|
||||
const ValidationMessage(this.message, { this.contextUrl, String? piiStrippedMessage })
|
||||
: type = ValidationMessageType.information, piiStrippedMessage = piiStrippedMessage ?? message;
|
||||
|
||||
/// Create a validation message with information for a failing validator.
|
||||
const ValidationMessage.error(this.message)
|
||||
const ValidationMessage.error(this.message, { String? piiStrippedMessage })
|
||||
: type = ValidationMessageType.error,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message,
|
||||
contextUrl = null;
|
||||
|
||||
/// Create a validation message with information for a partially failing
|
||||
/// validator.
|
||||
const ValidationMessage.hint(this.message)
|
||||
const ValidationMessage.hint(this.message, { String? piiStrippedMessage })
|
||||
: type = ValidationMessageType.hint,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message,
|
||||
contextUrl = null;
|
||||
|
||||
final ValidationMessageType type;
|
||||
final String? contextUrl;
|
||||
final String message;
|
||||
/// Optional message with PII stripped, to show instead of [message].
|
||||
final String piiStrippedMessage;
|
||||
|
||||
bool get isError => type == ValidationMessageType.error;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../doctor.dart';
|
||||
import '../project.dart';
|
||||
import 'github_template.dart';
|
||||
import 'reporting.dart';
|
||||
@@ -49,7 +50,7 @@ class CrashDetails {
|
||||
final String command;
|
||||
final Object error;
|
||||
final StackTrace stackTrace;
|
||||
final String doctorText;
|
||||
final DoctorText doctorText;
|
||||
}
|
||||
|
||||
/// Reports information about the crash to the user.
|
||||
@@ -92,7 +93,7 @@ class CrashReporter {
|
||||
details.command,
|
||||
details.error,
|
||||
details.stackTrace,
|
||||
details.doctorText,
|
||||
await details.doctorText.piiStrippedText,
|
||||
);
|
||||
_logger.printStatus('$gitHubTemplateURL\n', wrap: false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user