Unverified Commit 28d70769 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

toolexit on malformed yaml (#123167)

[flutter_tools] toolexit on malformed yaml during gen-l10n
parent 4be45e95
......@@ -5,6 +5,7 @@
import 'package:meta/meta.dart';
import 'package:yaml/yaml.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import 'gen_l10n_types.dart';
......@@ -436,7 +437,12 @@ LocalizationOptions parseLocalizationsOptions({
if (contents.trim().isEmpty) {
return const LocalizationOptions();
}
final YamlNode yamlNode = loadYamlNode(file.readAsStringSync());
final YamlNode yamlNode;
try {
yamlNode = loadYamlNode(file.readAsStringSync());
} on YamlException catch (err) {
throwToolExit(err.message);
}
if (yamlNode is! YamlMap) {
logger.printError('Expected ${file.path} to contain a map, instead was $yamlNode');
throw Exception();
......
......@@ -98,4 +98,19 @@ use-deferred-loading: string
throwsException,
);
});
testWithoutContext('parseLocalizationsOptions tool exits on malformed Yaml', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final File configFile = fileSystem.file('l10n.yaml')..writeAsStringSync('''
template-arb-file: {name}_en.arb
''');
expect(
() => parseLocalizationsOptions(
file: configFile,
logger: BufferLogger.test(),
),
throwsToolExit(),
);
});
}
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