Unverified Commit 4ce27ea0 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] update metadata detection to account for invalid yaml (#68243)

parent a69e393d
...@@ -85,7 +85,12 @@ class FlutterProjectMetadata { ...@@ -85,7 +85,12 @@ class FlutterProjectMetadata {
if (!_metadataFile.existsSync()) { if (!_metadataFile.existsSync()) {
return null; return null;
} }
final dynamic metadataYaml = loadYaml(_metadataFile.readAsStringSync()); dynamic metadataYaml;
try {
metadataYaml = loadYaml(_metadataFile.readAsStringSync());
} on YamlException {
// Handled in return below.
}
if (metadataYaml is YamlMap) { if (metadataYaml is YamlMap) {
_metadataYaml = metadataYaml; _metadataYaml = metadataYaml;
} else { } else {
......
...@@ -41,6 +41,17 @@ void main() { ...@@ -41,6 +41,17 @@ void main() {
expect(logger.traceText, contains('.metadata version is malformed.')); expect(logger.traceText, contains('.metadata version is malformed.'));
}); });
testWithoutContext('project metadata fields are empty when file is not valid yaml', () {
metadataFile.writeAsStringSync(' channel: @something');
final FlutterProjectMetadata projectMetadata = FlutterProjectMetadata(metadataFile, logger);
expect(projectMetadata.projectType, isNull);
expect(projectMetadata.versionChannel, isNull);
expect(projectMetadata.versionRevision, isNull);
expect(logger.traceText, contains('.metadata project_type version is malformed.'));
expect(logger.traceText, contains('.metadata version is malformed.'));
});
testWithoutContext('projectType is populated when version is malformed', () { testWithoutContext('projectType is populated when version is malformed', () {
metadataFile metadataFile
..createSync() ..createSync()
......
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