Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!isValid && typeof defaultValue === 'undefined' && !fromEnv) {
debug('Var statuses ','!isValid',!isValid,'typeof defaultValue',
typeof defaultValue, '!fromEnv',!fromEnv);
throw new Error('No config value found for: '+propertyName);
}
// either return found value or default
if (!fromEnv) {
debug('Propery '+envPropName+' gotten from config file: ',(isValid ? currVal : defaultValue));
return isValid ? currVal : defaultValue;
} else {
debug('Attempting to coercion checks.');
if (is.num(currVal)) {
debug('Coercing env '+envPropName+' to a numeric.');
return Number(envStr);
} else if (is.array(currVal)) {
debug('Coercing env '+envPropName+' to an array.');
if (/^\[(.)*\]$/.match(envStr)) {
envStr = envStr.substr(1); // remove '['
envStr = envStr.substring(0, envStr.length-1);
var elems = envStr.split(',');
for (var i=0; i
return asyncerr(new Error('Task has no fileName: '+inspect(task)), cb);
try {
// convert array representing a buffer into a string
if (is.array(task.file))
task.file = new Buffer(task.file);
} catch(err) {
return asyncerr(err, cb);
}
// ensure we have a string representing the file
if (!is.buffer(task.file))
return asyncerr(new Error('Task has no task.file: '+
inspect(task.file)), cb);
if (!is.array(task.args))
return asyncerr(new Error('Task has no args: '+inspect(task)), cb);
task.fileName = path.normalize(task.fileName);
// we want to dump the file in /tmp. If it is starts with /tmp, fine.
if (task.fileName.substr(0,4) !== '/tmp')
task.fileName = path.join('/tmp', task.fileName);
// get the dir and make the directory
var dir = path.dirname(task.fileName);
// place the output buffers in an object, so we can pass the object
// as a reference to the async function whose closure does not have the
// buffers
var output = { stdout: '', stderr: '' };
var iterator = function(cmd, cb) {
// default directorry is the cwd
if (!is.nonEmptyStr(cmd.dir)) cmd.dir = dir;
var output = ({stdout:'', stderr:''});
if (!is.nonEmptyStr(cmd.cmd) || !is.array(cmd.args))
return debug('Bad command '+inspect(cmd));
exports.runCmd(cmd.cmd, cmd.args, cmd.dir, output,
function(err, output, code) {
if (err) {
debug(inspect(err.message));
return cb(err);
}
codes.push(code);
outputs.push(output);
cb(null);
});
};
Worker.prototype.runFile = function(task, cb) {
debug('runFile task: '+inspect(task, {colors:true, depth:null}));
// ensure task is an object
if (!is.nonEmptyObj(task))
return asyncerr(new Error('No task received.'), cb);
// ensure the task has a filename
if (!is.str(task.fileName))
return asyncerr(new Error('Task has no fileName: '+inspect(task)), cb);
try {
// convert array representing a buffer into a string
if (is.array(task.file))
task.file = new Buffer(task.file);
} catch(err) {
return asyncerr(err, cb);
}
// ensure we have a string representing the file
if (!is.buffer(task.file))
return asyncerr(new Error('Task has no task.file: '+
inspect(task.file)), cb);
if (!is.array(task.args))
return asyncerr(new Error('Task has no args: '+inspect(task)), cb);
task.fileName = path.normalize(task.fileName);
// we want to dump the file in /tmp. If it is starts with /tmp, fine.
exports.runCmds = function(cmds, dir, cb) {
// it's valid to send no commands, you just get empty results.
if (is.nullOrUndef(cmds))
return cb(null, [], []);
if (!is.array(cmds))
return cb(new Error('Bad cmds parameter: '+inspect(cmds)));
if (!is.func(cb))
return cb(new Error('Bad cb parameter: '+inspect(cb)));
// one for each entry in the array
var outputs = [];
var codes = [];
// iterator function for async.eachSeries
var iterator = function(cmd, cb) {
// default directorry is the cwd
if (!is.nonEmptyStr(cmd.dir)) cmd.dir = dir;
var output = ({stdout:'', stderr:''});
if (!is.nonEmptyStr(cmd.cmd) || !is.array(cmd.args))
var self = this;
if (!is.func(task) && !is.obj(task))
return asyncerr(new Error('Bad task object: '+inspect(task)),cb);
if (!is.nonEmptyObj(worker))
return asyncerr(new Error('Bad parameter for worker: '+
inspect(worker)), cb);
if (!is.func(cb))
debug('Master.taskAll received no callback function.');
// args is an optional argument and may not be present
if (is.func(args)) {
cb = args;
} else if (is.array(args)) {
if (is.obj(task) && !task.args) {
task.args = args;
args = undefined;
}
}
// depending on the type of task, handle it
process.nextTick(function() {
if (is.func(task)) {
self.sendFuncToWorker(worker, task, args, cb);
} else if (is.obj(task)) {
switch(task.type) {
case 'github':
self.sendGithubToWorker(worker, task, cb);
break;
case 'file':