From 73c7f8713b703fc27505bed11774a7da998023ac Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 8 Feb 2018 18:15:49 +0200 Subject: [PATCH] feature(package) try-catch v2.0.0 --- bin/cloudcmd.js | 8 +++----- package.json | 2 +- server/config.js | 7 +++---- server/terminal.js | 12 +++++------- test/common/cloudfunc.js | 1 - 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 1e16399e..e4f49bd5 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -202,11 +202,9 @@ function readConfig(name) { mode: 'json' }); - let data; - - const error = tryCatch(() => { - data = readjsonSync(name); - }); + const result = tryCatch(readjsonSync, name); + const error = result[0]; + const data = result[1]; if (error) return exit(error.message); diff --git a/package.json b/package.json index bb4be2c5..32c92303 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "spero": "^2.0.0", "squad": "^1.1.3", "table": "^4.0.1", - "try-catch": "^1.0.0", + "try-catch": "^2.0.0", "tryrequire": "^1.1.5", "wraptile": "^1.0.0", "writejson": "^1.1.0" diff --git a/server/config.js b/server/config.js index 1ef5be04..85983609 100644 --- a/server/config.js +++ b/server/config.js @@ -48,10 +48,9 @@ const readjsonSync = (name) => { const rootConfig = readjsonSync(ConfigPath); const key = (a) => Object.keys(a).pop(); -let configHome; -const error = tryCatch(() => { - configHome = readjsonSync(ConfigHome); -}); +const result = tryCatch(readjsonSync, ConfigHome); +const error = result[0]; +const configHome = result[1]; if (error && error.code !== 'ENOENT') exit(`cloudcmd --config ${ConfigHome}: ${error.message}`); diff --git a/server/terminal.js b/server/terminal.js index 04689966..d15d024a 100644 --- a/server/terminal.js +++ b/server/terminal.js @@ -14,17 +14,15 @@ function getTerminal(term, arg) { if (!term) return noop; - let result; - - const e = tryCatch(() => { - result = require(config('terminalPath')); - }); + const result = tryCatch(require, config('terminalPath')); + const e = result[0]; + const terminalModule = result[1]; if (!e && !arg) - return result; + return terminalModule; if (!e) - return result(arg); + return terminalModule(arg); config('terminal', false); console.log(`cloudcmd --terminal: ${e.message}`); diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js index f3ad9102..12860de8 100644 --- a/test/common/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -222,7 +222,6 @@ test('cloudfunc: getDotDot', (t) => { test('cloudfunc: getDotDot: two levels deep', (t) => { const dotDot = CloudFunc.getDotDot('/home/coderaiser/'); - console.log(dotDot); t.equal(dotDot, '/home', 'should return up level'); t.end();