From a261fdf430cb754a32d5084300dcd28efd6605cc Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 14 Sep 2020 21:53:01 -0400 Subject: [PATCH] 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 --- src/node/hooks/i18n.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node/hooks/i18n.js b/src/node/hooks/i18n.js index 2265978b..0928b293 100644 --- a/src/node/hooks/i18n.js +++ b/src/node/hooks/i18n.js @@ -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); }); });