Add a better error message when flutter drive --target is used incorrectly. (#162023)

Closes https://github.com/flutter/flutter/issues/62626.
This commit is contained in:
Matan Lurey
2025-01-22 20:39:13 -08:00
committed by GitHub
parent 1083356201
commit 9c960ff7da
2 changed files with 97 additions and 0 deletions

View File

@@ -284,6 +284,15 @@ class DriveCommand extends RunCommandBase {
throwToolExit(null);
}
if (await _fileSystem.type(testFile) != FileSystemEntityType.file) {
// A very common source of error is holding "flutter drive" wrong,
// and providing the "test_driver/foo_test.dart" as the target, when
// the intention was to provide "lib/foo.dart".
if (_fileSystem.path.isWithin('test_driver', targetFile)) {
_logger.printError(
'The file path passed to --target should be an app entrypoint that '
'contains a "main()". Did you mean "flutter drive --driver $targetFile"?',
);
}
throwToolExit('Test file not found: $testFile');
}
final Device? device = await targetedDevice;