Do not silently fail pub get even if output-mode is "none" (#153596)

I am making an assumption `OutputMode.none` should _really_ mean
`OutputMode.failuresOnly`, that is, if we ever get a non-zero exit code,
we still want to know why. If I've somehow misunderstood that, LMK and
I'm happy to revert this PR or make adjustments.

This fixes the bug where if you were to do:

```sh
git clone https://github.com/myuser/fork-of-flutter
cd fork-of-flutter
./bin/flutter update-packages
```

You now get:

1. An actual error message, versus no output at all.
2. A warning that a common reason is not tracking a remote, with
instructions to fix it.

Closes https://github.com/flutter/flutter/issues/148569.
This commit is contained in:
Matan Lurey
2024-08-22 09:12:54 -07:00
committed by GitHub
parent 544ce7cd34
commit a9e94d9045
6 changed files with 100 additions and 19 deletions

View File

@@ -1039,7 +1039,7 @@ void main() {
expect(
pub.invocations.first,
predicate<FakePubInvocation>(
(FakePubInvocation invocation) => invocation.outputMode == PubOutputMode.none,
(FakePubInvocation invocation) => invocation.outputMode == PubOutputMode.failuresOnly,
'Pub invoked with PubOutputMode.none',
),
);

View File

@@ -616,7 +616,7 @@ exit code: 66
context: PubContext.flutterTests,
),
throwsA(isA<ToolExit>()
.having((ToolExit error) => error.message, 'message', null)),
.having((ToolExit error) => error.message, 'message', contains('Failed to update packages'))),
);
expect(logger.statusText, isEmpty);
expect(logger.traceText, contains(toolExitMessage));
@@ -629,6 +629,62 @@ exit code: 66
expect(processManager, hasNoRemainingExpectations);
});
testWithoutContext('pub get with failing exit code even with OutputMode == failuresOnly', () async {
final BufferLogger logger = BufferLogger.test();
final FileSystem fileSystem = MemoryFileSystem.test();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'bin/cache/dart-sdk/bin/dart',
'pub',
'--suppress-analytics',
'--directory',
'.',
'get',
'--example',
],
exitCode: 1,
stderr: '===pub get failed stderr here===',
stdout: 'out1\nout2\nout3\n',
environment: <String, String>{
'FLUTTER_ROOT': '',
'PUB_ENVIRONMENT': 'flutter_cli:update_packages'
},
),
]);
// Intentionally not using pub.test to simulate a real environment, but
// we are using non-inherited I/O to avoid printing to the console.
final Pub pub = Pub(
platform: FakePlatform(),
fileSystem: fileSystem,
logger: logger,
usage: TestUsage(),
botDetector: const BotDetectorAlwaysNo(),
processManager: processManager,
);
await expectLater(
() => pub.get(
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
context: PubContext.updatePackages,
outputMode: PubOutputMode.failuresOnly,
),
throwsToolExit(
message: 'Failed to update packages',
),
);
expect(logger.statusText, isEmpty);
expect(logger.errorText, contains('===pub get failed stderr here==='));
expect(
logger.warningText,
contains('git remote set-url upstream'),
reason: 'When update-packages fails, it is often because of missing an upsteam remote.',
);
expect(processManager, hasNoRemainingExpectations);
});
testWithoutContext('pub get shows working directory on process exception',
() async {
final BufferLogger logger = BufferLogger.test();
@@ -745,7 +801,7 @@ exit code: 66
await pub.get(
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
context: PubContext.flutterTests,
outputMode: PubOutputMode.none,
outputMode: PubOutputMode.failuresOnly,
);
} on ToolExit {
// Ignore.