Don't crash on invalid .packages file in initial run(#34527)
This commit is contained in:
@@ -545,7 +545,16 @@ class FlutterCommandRunner extends CommandRunner<void> {
|
||||
// Check that the flutter running is that same as the one referenced in the pubspec.
|
||||
if (fs.isFileSync(kPackagesFileName)) {
|
||||
final PackageMap packageMap = PackageMap(kPackagesFileName);
|
||||
final Uri flutterUri = packageMap.map['flutter'];
|
||||
Uri flutterUri;
|
||||
try {
|
||||
flutterUri = packageMap.map['flutter'];
|
||||
} on FormatException {
|
||||
// We're not quite sure why this can happen, perhaps the user
|
||||
// accidentally edited the .packages file. Re-running pub should
|
||||
// fix the issue, and we definitely shouldn't crash here.
|
||||
printTrace('Failed to parse .packages file to check flutter dependency.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (flutterUri != null && (flutterUri.scheme == 'file' || flutterUri.scheme == '')) {
|
||||
// .../flutter/packages/flutter/lib
|
||||
|
||||
@@ -103,6 +103,19 @@ void main() {
|
||||
}, initializeFlutterRoot: false);
|
||||
});
|
||||
|
||||
testUsingContext('Doesnt crash on invalid .packages file', () async {
|
||||
fs.file('pubspec.yaml').createSync();
|
||||
fs.file('.packages')
|
||||
..createSync()
|
||||
..writeAsStringSync('Not a valid package');
|
||||
|
||||
await runner.run(<String>['dummy']);
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
Platform: () => platform,
|
||||
}, initializeFlutterRoot: false);
|
||||
|
||||
group('version', () {
|
||||
testUsingContext('checks that Flutter toJson output reports the flutter framework version', () async {
|
||||
final ProcessResult result = ProcessResult(0, 0, 'random', '0');
|
||||
|
||||
Reference in New Issue
Block a user