[flutter_tools] Add more info to pub get failure event (#41652)

This commit is contained in:
Zachary Anderson
2019-10-03 11:08:42 -07:00
committed by GitHub
parent 517c08e801
commit c7c8a6c498
11 changed files with 197 additions and 84 deletions

View File

@@ -6,6 +6,7 @@ import 'dart:async';
import '../convert.dart';
import '../globals.dart';
import 'common.dart';
import 'context.dart';
import 'file_system.dart';
import 'io.dart';
@@ -470,10 +471,13 @@ class _DefaultProcessUtils implements ProcessUtils {
stderrSubscription.asFuture<void>(),
]);
await waitGroup<void>(<Future<void>>[
stdoutSubscription.cancel(),
stderrSubscription.cancel(),
]);
// The streams as futures have already completed, so waiting for the
// potentially async stream cancellation to complete likely has no benefit.
// Further, some Stream implementations commonly used in tests don't
// complete the Future returned here, which causes tests using
// mocks/FakeAsync to fail when these Futures are awaited.
unawaited(stdoutSubscription.cancel());
unawaited(stderrSubscription.cancel());
return await process.exitCode;
}

View File

@@ -100,12 +100,10 @@ class PackagesGetCommand extends FlutterCommand {
checkLastModified: false,
);
pubGetTimer.stop();
PubGetEvent(success: true).send();
flutterUsage.sendTiming('packages-pub-get', 'success', pubGetTimer.elapsed);
flutterUsage.sendTiming('pub', 'get', pubGetTimer.elapsed, label: 'success');
} catch (_) {
pubGetTimer.stop();
PubGetEvent(success: false).send();
flutterUsage.sendTiming('packages-pub-get', 'failure', pubGetTimer.elapsed);
flutterUsage.sendTiming('pub', 'get', pubGetTimer.elapsed, label: 'failure');
rethrow;
}
}

View File

@@ -15,6 +15,7 @@ import '../base/process.dart';
import '../base/utils.dart';
import '../cache.dart';
import '../globals.dart';
import '../reporting/reporting.dart';
import '../runner/flutter_command.dart';
import 'sdk.dart';
@@ -54,6 +55,10 @@ class PubContext {
@override
String toString() => 'PubContext: ${_values.join(':')}';
String toAnalyticsString() {
return _values.map((String s) => s.replaceAll('_', '-')).toList().join('-');
}
}
bool _shouldRunPubGet({ File pubSpecYaml, File dotPackages }) {
@@ -128,7 +133,9 @@ Future<void> pubGet({
}
if (dotPackages.lastModifiedSync().isBefore(pubSpecYaml.lastModifiedSync())) {
throwToolExit('$directory: pub did not update .packages file (pubspec.yaml timestamp: ${pubSpecYaml.lastModifiedSync()}; .packages timestamp: ${dotPackages.lastModifiedSync()}).');
throwToolExit('$directory: pub did not update .packages file '
'(pubspec.yaml timestamp: ${pubSpecYaml.lastModifiedSync()}; '
'.packages timestamp: ${dotPackages.lastModifiedSync()}).');
}
}
@@ -155,6 +162,17 @@ Future<void> pub(
}) async {
showTraceForErrors ??= isRunningOnBot;
bool versionSolvingFailed = false;
String filterWrapper(String line) {
if (line.contains('version solving failed')) {
versionSolvingFailed = true;
}
if (filter == null) {
return line;
}
return filter(line);
}
if (showTraceForErrors) {
arguments.insert(0, '--trace');
}
@@ -166,12 +184,13 @@ Future<void> pub(
code = await processUtils.stream(
_pubCommand(arguments),
workingDirectory: directory,
mapFunction: filter,
mapFunction: filterWrapper,
environment: _createPubEnvironment(context),
);
if (code != 69) { // UNAVAILABLE in https://github.com/dart-lang/pub/blob/master/lib/src/exit_codes.dart
break;
}
versionSolvingFailed = false;
printStatus('$failureMessage ($code) -- attempting retry $attempts in $duration second${ duration == 1 ? "" : "s"}...');
await Future<void>.delayed(Duration(seconds: duration));
if (duration < 64) {
@@ -179,6 +198,18 @@ Future<void> pub(
}
}
assert(code != null);
String result = 'success';
if (versionSolvingFailed) {
result = 'version-solving-failed';
} else if (code != 0) {
result = 'failure';
}
PubResultEvent(
context: context.toAnalyticsString(),
result: result,
).send();
if (code != 0) {
throwToolExit('$failureMessage ($code)', exitCode: code);
}

View File

@@ -27,7 +27,7 @@ class DisabledUsage implements Usage {
void sendCommand(String command, { Map<String, String> parameters }) { }
@override
void sendEvent(String category, String parameter, { Map<String, String> parameters }) { }
void sendEvent(String category, String parameter, { String label, Map<String, String> parameters }) { }
@override
void sendTiming(String category, String variableName, Duration duration, { String label }) { }

View File

@@ -9,13 +9,16 @@ part of reporting;
/// If sending values for custom dimensions is required, extend this class as
/// below.
class UsageEvent {
UsageEvent(this.category, this.parameter);
UsageEvent(this.category, this.parameter, {
this.label,
});
final String category;
final String parameter;
final String label;
void send() {
flutterUsage.sendEvent(category, parameter);
flutterUsage.sendEvent(category, parameter, label: label);
}
}
@@ -101,7 +104,7 @@ class DoctorResultEvent extends UsageEvent {
@override
void send() {
if (validator is! GroupedValidator) {
flutterUsage.sendEvent(category, parameter);
flutterUsage.sendEvent(category, parameter, label: label);
return;
}
final GroupedValidator group = validator;
@@ -114,10 +117,11 @@ class DoctorResultEvent extends UsageEvent {
}
/// An event that reports success or failure of a pub get.
class PubGetEvent extends UsageEvent {
PubGetEvent({
@required bool success,
}) : super('packages-pub-get', success ? 'success' : 'failure');
class PubResultEvent extends UsageEvent {
PubResultEvent({
@required String context,
@required String result,
}) : super('pub', context, label: result);
}
/// An event that reports something about a build.

View File

@@ -124,6 +124,7 @@ abstract class Usage {
void sendEvent(
String category,
String parameter, {
String label,
Map<String, String> parameters,
});
@@ -262,6 +263,7 @@ class _DefaultUsage implements Usage {
void sendEvent(
String category,
String parameter, {
String label,
Map<String, String> parameters,
}) {
if (suppressAnalytics) {
@@ -273,7 +275,12 @@ class _DefaultUsage implements Usage {
cdKey(CustomDimensions.localTime): formatDateTime(systemClock.now()),
};
_analytics.sendEvent(category, parameter, parameters: paramsWithLocalTime);
_analytics.sendEvent(
category,
parameter,
label: label,
parameters: paramsWithLocalTime,
);
}
@override