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 { ...@@ -266,17 +266,10 @@ class _DefaultPub implements Pub {
} catch (exception) { // ignore: avoid_catches_without_on_clauses } catch (exception) { // ignore: avoid_catches_without_on_clauses
status?.cancel(); status?.cancel();
if (exception is io.ProcessException) { if (exception is io.ProcessException) {
final StringBuffer buffer = StringBuffer(exception.message); final StringBuffer buffer = StringBuffer('${exception.message}\n');
buffer.writeln('Working directory: "$directory"'); buffer.writeln('Working directory: "$directory"');
final Map<String, String> env = await _createPubEnvironment(context, flutterRootOverride); final Map<String, String> env = await _createPubEnvironment(context, flutterRootOverride);
if (env.entries.isNotEmpty) { buffer.write(_stringifyPubEnv(env));
buffer.writeln('pub env: {');
for (final MapEntry<String, String> entry in env.entries) {
buffer.writeln(' "${entry.key}": "${entry.value}",');
}
buffer.writeln('}');
}
throw io.ProcessException( throw io.ProcessException(
exception.executable, exception.executable,
exception.arguments, exception.arguments,
...@@ -298,6 +291,20 @@ class _DefaultPub implements Pub { ...@@ -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 @override
Future<void> batch( Future<void> batch(
List<String> arguments, { List<String> arguments, {
...@@ -330,13 +337,15 @@ class _DefaultPub implements Pub { ...@@ -330,13 +337,15 @@ class _DefaultPub implements Pub {
int attempts = 0; int attempts = 0;
int duration = 1; int duration = 1;
int code; int code;
final List<String> pubCommand = _pubCommand(arguments);
final Map<String, String> pubEnvironment = await _createPubEnvironment(context, flutterRootOverride);
while (true) { while (true) {
attempts += 1; attempts += 1;
code = await _processUtils.stream( code = await _processUtils.stream(
_pubCommand(arguments), pubCommand,
workingDirectory: directory, workingDirectory: directory,
mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage mapFunction: filterWrapper, // may set versionSolvingFailed, lastPubMessage
environment: await _createPubEnvironment(context, flutterRootOverride), environment: pubEnvironment,
); );
String? message; String? message;
if (retry) { if (retry) {
...@@ -372,7 +381,15 @@ class _DefaultPub implements Pub { ...@@ -372,7 +381,15 @@ class _DefaultPub implements Pub {
).send(); ).send();
if (code != 0) { 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() { ...@@ -611,7 +611,7 @@ void main() {
); );
}); });
expect(logger.errorText, isEmpty); 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); expect(processManager, hasNoRemainingExpectations);
}); });
...@@ -643,9 +643,19 @@ void main() { ...@@ -643,9 +643,19 @@ void main() {
botDetector: const BotDetectorAlwaysNo(), botDetector: const BotDetectorAlwaysNo(),
processManager: processManager, 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( await expectLater(
() => pub.get(context: PubContext.flutterTests), () => 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, expect(logger.statusText,
'Running "flutter pub get" in /...\n' '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