more info on bad JSON

pull/377/head^2
Gordon Williams 2020-05-04 09:28:27 +01:00
parent 799e65baf9
commit d206ff07c7
1 changed files with 13 additions and 1 deletions

View File

@ -27,14 +27,26 @@ function WARN(s) {
var appsFile, apps; var appsFile, apps;
try { try {
appsFile = fs.readFileSync(BASEDIR+"apps.json"); appsFile = fs.readFileSync(BASEDIR+"apps.json").toString();
} catch (e) { } catch (e) {
ERROR("apps.json not found"); ERROR("apps.json not found");
} }
try{ try{
apps = JSON.parse(appsFile); apps = JSON.parse(appsFile);
} catch (e) { } catch (e) {
console.log(e);
var m = e.toString().match(/in JSON at position (\d+)/);
if (m) {
var char = parseInt(m[1]);
console.log("===============================================");
console.log("LINE "+appsFile.substr(0,char).split("\n").length);
console.log("===============================================");
console.log(appsFile.substr(char-10, 20));
console.log("===============================================");
}
console.log(m);
ERROR("apps.json not valid JSON"); ERROR("apps.json not valid JSON");
} }
const APP_KEYS = [ const APP_KEYS = [