Unverified Commit 0d4f4bdd authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Don't crash on invalid .packages file in initial run(#34527)

parent 49449505
...@@ -545,7 +545,16 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -545,7 +545,16 @@ class FlutterCommandRunner extends CommandRunner<void> {
// Check that the flutter running is that same as the one referenced in the pubspec. // Check that the flutter running is that same as the one referenced in the pubspec.
if (fs.isFileSync(kPackagesFileName)) { if (fs.isFileSync(kPackagesFileName)) {
final PackageMap packageMap = PackageMap(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 == '')) { if (flutterUri != null && (flutterUri.scheme == 'file' || flutterUri.scheme == '')) {
// .../flutter/packages/flutter/lib // .../flutter/packages/flutter/lib
......
...@@ -103,6 +103,19 @@ void main() { ...@@ -103,6 +103,19 @@ void main() {
}, initializeFlutterRoot: false); }, 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', () { group('version', () {
testUsingContext('checks that Flutter toJson output reports the flutter framework version', () async { testUsingContext('checks that Flutter toJson output reports the flutter framework version', () async {
final ProcessResult result = ProcessResult(0, 0, 'random', '0'); final ProcessResult result = ProcessResult(0, 0, 'random', '0');
......
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