feature(package) try-catch v2.0.0

This commit is contained in:
coderaiser 2018-02-08 18:15:49 +02:00
parent 7acf191f61
commit 73c7f8713b
5 changed files with 12 additions and 18 deletions

View file

@ -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);

View file

@ -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"

View file

@ -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}`);

View file

@ -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}`);

View file

@ -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();