better errors when parsing invalid json

This commit is contained in:
Iuri Matias 2017-12-19 12:57:03 -05:00
parent ee43f58c15
commit bc34e00268
2 changed files with 10 additions and 1 deletions

View File

@ -1,5 +1,7 @@
const parseJson = require('parse-json');
let fs = require('fs-extra');
let utils = require('../utils/utils.js');
require('colors');
function mkdirpSync() {
return fs.mkdirpSync.apply(fs.mkdirpSync, arguments);
@ -18,7 +20,13 @@ function readFileSync() {
}
function readJSONSync() {
return fs.readJSONSync.apply(fs.readJSONSync, arguments);
let content = readFileSync.apply(readFileSync, arguments);
try {
return parseJson(content);
} catch(e) {
console.error("error: ".red + arguments[0].green.underline + " " + e.message.green);
process.exit(0);
}
}
function writeJSONSync() {

View File

@ -39,6 +39,7 @@
"merge": "^1.2.0",
"mocha": "^2.2.5",
"orbit-db": "^0.17.3",
"parse-json": "^4.0.0",
"promptly": "^2.1.0",
"serve-static": "^1.11.1",
"shelljs": "^0.5.0",