From 6efbef5210a2976d0c4890f1fa06c46611c85fdf Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 12 Jul 2015 03:45:21 -0400 Subject: [PATCH] feature(config) show error.message when file exist, but could not be read from home --- lib/server/config.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/server/config.js b/lib/server/config.js index 63b271a2..2a24ff15 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -9,6 +9,7 @@ path = require('path'), password = require(DIR_SERVER + 'password'), + exit = require(DIR_SERVER + 'exit'), Util = require(DIR_LIB + 'util'), CloudFunc = require(DIR_LIB + 'cloudfunc'), @@ -17,6 +18,7 @@ ponse = require('ponse'), jonny = require('jonny'), readjson = require('readjson'), + tryCatch = require('try-catch'), HOME = require('os-homedir')(), apiURL = CloudFunc.apiURL, @@ -24,9 +26,24 @@ ConfigPath = path.join(DIR, 'json/config.json'), ConfigHome = path.join(HOME, '.cloudcmd.json'), - config = - readjson.sync.try(ConfigHome) || - readjson.sync.try(ConfigPath); + error, + config; + + error = tryCatch(function() { + config = readjson.sync(ConfigHome); + }); + + if (error) { + if (error.code !== 'ENOENT') + console.error('cloudcmd --config ~/.cloudcmd.json:', error.message); + + error = tryCatch(function() { + config = readjson.sync(ConfigPath); + }); + + if (error) + exit('cloudcmd --config', ConfigPath + ':', error.message); + } module.exports = manage; module.exports.save = save;