From 99d55be497c979bd10255c2d84ac214756b5697c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 7 Apr 2015 06:26:17 -0400 Subject: [PATCH] feature(config) tryrequire -> try-catch --- lib/server/config.js | 18 +++++++++++++++--- lib/server/root.js | 5 ++++- package.json | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/server/config.js b/lib/server/config.js index c76a3999..b026ee9c 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -17,7 +17,7 @@ CloudFunc = require(DIR_LIB + 'cloudfunc'), check = require('checkup'), - tryRequire = require('tryrequire'), + tryCatch = require('try-catch'), pipe = require('pipe-io'), ponse = require('ponse'), json = require('jonny'), @@ -29,12 +29,24 @@ config = tryRequire(ConfigHome) || - tryRequire(ConfigPath, {log: true}) || {}; - + tryRequire(ConfigPath); + module.exports = manage; module.exports.save = save; module.exports.socket = socket; + function tryRequire(path) { + var ret, + error = tryCatch(function() { + ret = require(path); + }); + + if (error && error.code !== 'MODULE_NOT_FOUND') + console.error(error.message); + + return ret; + } + function manage(key, value) { var result; diff --git a/lib/server/root.js b/lib/server/root.js index a05aa3f4..8fcea13a 100644 --- a/lib/server/root.js +++ b/lib/server/root.js @@ -4,7 +4,8 @@ var DIR = './', path = require('path'), config = require(DIR + 'config'), - mellow = require('mellow'); + mellow = require('mellow'), + log = require('debug')('cloudcmd-root'); module.exports = function(dir) { var root = config('root') || '/'; @@ -14,6 +15,8 @@ else dir = path.join(root + dir); + log(dir); + return dir; }; })(); diff --git a/package.json b/package.json index ac8ff9c8..e37de7ee 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "checkup": "~1.0.3", "console-io": "~2.2.0", "copymitter": "~1.6.0", + "debug": "~2.1.3", "dword": "~1.3.2", "edward": "~1.4.0", "execon": "~1.1.0", @@ -55,6 +56,7 @@ "rendy": "~1.0.2", "restafary": "~1.2.0", "socket.io": "~1.3.5", + "try-catch": "~1.0.0", "tryrequire": "~1.1.5" }, "devDependencies": {