toolexit on malformed yaml (#123167)
[flutter_tools] toolexit on malformed yaml during gen-l10n
This commit is contained in:
committed by
GitHub
parent
4be45e950d
commit
28d707693b
@@ -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(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user