From 81c346710fabb7b393c557a5c2fb4b8999c44faf Mon Sep 17 00:00:00 2001 From: Alan Pierce Date: Sat, 3 Sep 2016 12:16:43 -0700 Subject: [PATCH] fix: improve error handling when a config file is invalid json (#11) It still isn't great, but it says the file that's wrong and the fact that it was invalid JSON. --- src/config/resolveConfig.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config/resolveConfig.js b/src/config/resolveConfig.js index c3963c7..404e768 100644 --- a/src/config/resolveConfig.js +++ b/src/config/resolveConfig.js @@ -21,8 +21,13 @@ export default async function resolveConfig(commander) { if (filename.startsWith('bulk-decaffeinate') && filename.endsWith('.json') && !(await stat(filename)).isDirectory()) { - let newConfig = JSON.parse(await readFile(filename)); - config = Object.assign(config, newConfig); + try { + let newConfig = JSON.parse(await readFile(filename)); + config = Object.assign(config, newConfig); + } catch (e) { + throw new CLIError( + `Error reading file ${filename}. Make sure it is a valid JSON file.`); + } } } config = Object.assign(config, getCLIParamsConfig(commander));