Improve arb FormatException error message (#56373)

This commit is contained in:
Shi-Hao Hong
2020-05-07 18:09:03 -07:00
committed by GitHub
parent 26dc70dc18
commit eadd30eb6c
2 changed files with 41 additions and 27 deletions

View File

@@ -363,8 +363,16 @@ class AppResourceBundle {
factory AppResourceBundle(File file) {
assert(file != null);
// Assuming that the caller has verified that the file exists and is readable.
Map<String, dynamic> resources;
try {
resources = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
} on FormatException catch (e) {
throw L10nException(
'The arb file ${file.path} has the following formatting issue: \n'
'${e.toString()}',
);
}
final Map<String, dynamic> resources = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
String localeString = resources['@@locale'] as String;
if (localeString == null) {
final RegExp filenameRE = RegExp(r'^[^_]*_(\w+)\.arb$');