i18n: Improve error logging when language JSON read fails

Before it only logged an error like this:

    SyntaxError: Unexpected string in JSON at position XYZ

Now it also logs the filename, making it easier to figure out where
the bad data is:

    failed to read file /path/to/etherpad-lite/src/locales/en.json: SyntaxError: Unexpected string in JSON at position XYZ
This commit is contained in:
Richard Hansen 2020-09-14 21:53:01 -04:00 committed by John McLear
parent 38352c1f8c
commit a261fdf430
1 changed files with 7 additions and 1 deletions

View File

@ -50,7 +50,13 @@ function getAllLocales() {
locales[langcode]={};
files.forEach(function(file) {
var fileContents = JSON.parse(fs.readFileSync(file,'utf8'));
let fileContents;
try {
fileContents = JSON.parse(fs.readFileSync(file,'utf8'));
} catch (err) {
console.error(`failed to read JSON file ${file}: ${err}`);
throw err;
}
_.extend(locales[langcode], fileContents);
});
});