Unverified Commit 6abd3691 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] add more debugging when pub get fails (#108062)

parent 092481d4
......@@ -266,17 +266,10 @@ class _DefaultPub implements Pub {
} catch (exception) { // ignore: avoid_catches_without_on_clauses
status?.cancel();
if (exception is io.ProcessException) {
final StringBuffer buffer = StringBuffer(exception.message);
final StringBuffer buffer = StringBuffer('${exception.message}\n');
buffer.writeln('Working directory: "$directory"');
final Map<String, String> env = await _createPubEnvironment(context, flutterRootOverride);
if (env.entries.isNotEmpty) {
buffer.writeln('pub env: {');
for (final MapEntry<String, String> entry in env.entries) {
buffer.writeln(' "${entry.key}": "${entry.value}",');
}
buffer.writeln('}');
}
buffer.write(_stringifyPubEnv(env));
throw io.ProcessException(
exception.executable,
exception.arguments,
......@@ -298,6 +291,20 @@ class _DefaultPub implements Pub {
);
}
// For surfacing pub env in crash reporting
String _stringifyPubEnv(Map<String, String> map, {String prefix = 'pub env'}) {
if (map.isEmpty) {
return '';
}
final StringBuffer buffer = StringBuffer();
buffer.writeln('$prefix: {');
for (final MapEntry<String, String> entry in map.entries) {
buffer.writeln(' "${entry.key}": "${entry.value}",');
}
buffer.writeln('}');
return buffer.toString();
}
@override
Future<void> batch(
List<String> arguments, {
......@@ -330,13 +337,15 @@ class _DefaultPub implements Pub {
int attempts = 0;
int duration = 1;
int code;
final List<String> pubCommand = _pubCommand(arguments);
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
while (true) {
attempts += 1;
code = await _processUtils.stream(
_pubCommand(arguments),
pubCommand,
workingDirectory: directory,
mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage
environment: await _createPubEnvironment(context, flutterRootOverride),
environment: pubEnvironment,
);
String? message;
if (retry) {
......@@ -372,7 +381,15 @@ class _DefaultPub implements Pub {
).send();
if (code != 0) {
throwToolExit('$failureMessage ($code; $lastPubMessage)', exitCode: code);
final StringBuffer buffer = StringBuffer('$failureMessage\n');
buffer.writeln('command: "${pubCommand.join(' ')}"');
buffer.write(_stringifyPubEnv(pubEnvironment));
buffer.writeln('exit code: $code');
buffer.writeln('last line of pub output: "${lastPubMessage.trim()}"');
throwToolExit(
buffer.toString(),
exitCode: code,
);
}
}
......
......@@ -611,7 +611,7 @@ void main() {
);
});
expect(logger.errorText, isEmpty);
expect(error, 'test failed unexpectedly: Exception: pub get failed (69; no message)');
expect(error, contains('test failed unexpectedly: Exception: pub get failed'));
expect(processManager, hasNoRemainingExpectations);
});
......@@ -643,9 +643,19 @@ void main() {
botDetector: const BotDetectorAlwaysNo(),
processManager: processManager,
);
const String toolExitMessage = '''
pub get failed
command: "bin/cache/dart-sdk/bin/dart __deprecated_pub --verbosity=warning get --no-precompile"
pub env: {
"FLUTTER_ROOT": "",
"PUB_ENVIRONMENT": "flutter_cli:flutter_tests",
}
exit code: 66
last line of pub output: "err3"
''';
await expectLater(
() => pub.get(context: PubContext.flutterTests),
throwsA(isA<ToolExit>().having((ToolExit error) => error.message, 'message', 'pub get failed (66; err3)')),
throwsA(isA<ToolExit>().having((ToolExit error) => error.message, 'message', toolExitMessage)),
);
expect(logger.statusText,
'Running "flutter pub get" in /...\n'
......
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