Unverified Commit 13382f41 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Catch a yaml parse failure during project creation (#36105)

parent aa6cc071
...@@ -16,6 +16,7 @@ import 'bundle.dart' as bundle; ...@@ -16,6 +16,7 @@ import 'bundle.dart' as bundle;
import 'cache.dart'; import 'cache.dart';
import 'desktop.dart'; import 'desktop.dart';
import 'flutter_manifest.dart'; import 'flutter_manifest.dart';
import 'globals.dart';
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
import 'ios/plist_utils.dart' as plist; import 'ios/plist_utils.dart' as plist;
import 'ios/xcodeproj.dart' as xcode; import 'ios/xcodeproj.dart' as xcode;
...@@ -177,9 +178,16 @@ class FlutterProject { ...@@ -177,9 +178,16 @@ class FlutterProject {
/// Completes with an empty [FlutterManifest], if the file does not exist. /// Completes with an empty [FlutterManifest], if the file does not exist.
/// Completes with a ToolExit on validation error. /// Completes with a ToolExit on validation error.
static FlutterManifest _readManifest(String path) { static FlutterManifest _readManifest(String path) {
final FlutterManifest manifest = FlutterManifest.createFromPath(path); FlutterManifest manifest;
if (manifest == null) try {
manifest = FlutterManifest.createFromPath(path);
} on YamlException catch (e) {
printStatus('Error detected in pubspec.yaml:', emphasis: true);
printError('$e');
}
if (manifest == null) {
throwToolExit('Please correct the pubspec.yaml file at $path'); throwToolExit('Please correct the pubspec.yaml file at $path');
}
return manifest; return manifest;
} }
......
...@@ -40,7 +40,19 @@ void main() { ...@@ -40,7 +40,19 @@ void main() {
expect( expect(
() => FlutterProject.fromDirectory(directory), () => FlutterProject.fromDirectory(directory),
throwsA(isInstanceOf<Exception>()), throwsA(isInstanceOf<ToolExit>()),
);
});
testInMemory('fails on pubspec.yaml parse failure', () async {
final Directory directory = fs.directory('myproject');
directory.childFile('pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(parseErrorPubspec);
expect(
() => FlutterProject.fromDirectory(directory),
throwsA(isInstanceOf<ToolExit>()),
); );
}); });
...@@ -52,7 +64,7 @@ void main() { ...@@ -52,7 +64,7 @@ void main() {
expect( expect(
() => FlutterProject.fromDirectory(directory), () => FlutterProject.fromDirectory(directory),
throwsA(isInstanceOf<Exception>()), throwsA(isInstanceOf<ToolExit>()),
); );
}); });
...@@ -575,6 +587,14 @@ flutter: ...@@ -575,6 +587,14 @@ flutter:
invalid: invalid:
'''; ''';
String get parseErrorPubspec => '''
name: hello
# Whitespace is important.
flutter:
something:
something_else:
''';
String projectFileWithBundleId(String id, {String qualifier}) { String projectFileWithBundleId(String id, {String qualifier}) {
return ''' return '''
97C147061CF9000F007C117D /* Debug */ = { 97C147061CF9000F007C117D /* Debug */ = {
......
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