How to use the common-errors.ArgumentNull function in common-errors

To help you get started, we’ve selected a few common-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shutterstock / fnFlow / tests / 002-flowTaskFunctions.js View on Github external
var testFunction = function(book, cb){
    cb(new errors.ArgumentNull('book'));
  };
github shutterstock / fnFlow / tests / tests.js View on Github external
var testFunction = function(book, cb){
    cb(new errors.ArgumentNull('book'));
  };
github shutterstock / fnFlow / lib / task.js View on Github external
var Task = module.exports = function(fn, args){
  if(!fn) throw new errors.ArgumentNull('fn');
  if(!/^(string|function)$/.test(typeof fn)) throw new TypeError('Task fn must be a string or a function');
  args = Array.prototype.slice.call(arguments, 1);
  for(var i=0; i
github shutterstock / fnFlow / lib / fnFlow.js View on Github external
Flow.prototype.execute = function execute(data, callback) {
  if(arguments.length == 1) {
    callback = data, data = {};
  }
  if(!callback) throw new errors.ArgumentNull('callback');
  return Execution.launch(this, data, callback);
}
github shutterstock / fnFlow / lib / task.js View on Github external
var cb = function(err, result){
      if(err && err.name == "ArgumentNullError" && flow.tasks[err.argumentName]) err.message = "Not Found: " + flow.tasks[err.argumentName].toString(results)
      if(err) return callback(err);
      if(arguments.length > 2) result = Array.prototype.slice.call(arguments, 1);
      return Task.complete.call(task, result, results, callback);
    };

    var fnArgs;
    try {
      //we will generate the list of args to apply to the fn.
      fnArgs = plan.args.map(function(arg){ 
        return evalMessages(results, arg, self.name);         
      });
    } catch(e) { 
      if(e.name == "FlowTaskArgumentNullError") {
        e = new errors.ArgumentNull(e.receiver_name);
        e.message = "Not Found During Flow: " + flow.tasks[self.name].toString(results, e.argumentName);
      }
      return callback(e); 
    }
    if(!self.is_sync) fnArgs.push(cb);

    var fn = plan.fn;
    var receiver;
    if(typeof plan.fn != 'function') {
      var fnName = plan.fn.name;
      var receiverName = plan.fn.receiverName;
      try {
        receiver = evalMessages(results, receiverName, self.name);
      } catch(e) { 
        if(e.name == "FlowTaskArgumentNullError") e.message = "Not Found During Flow: " + self.tasks[self.name].toString(results, e.argumentName);
        return callback(e);
github shutterstock / fnFlow / lib / execution.js View on Github external
var Execution = module.exports = function Execution(flow, data) {
  if(!flow) throw new errors.ArgumentNull('flow');
  if(!data) throw new errors.ArgumentNull('data');
  this.flow = flow;
  this.data = data;
  var context = this.context = flow.parent ? data[flow.context_name] : null;
}
github shutterstock / fnFlow / lib / execution.js View on Github external
Execution.launch = function launch(flow, data, callback) {
  if(!flow) return new errors.ArgumentNull('flow');
  if(!data) return new errors.ArgumentNull('data');

  if(data instanceof Array) {
    var execs = data.map(function(data, cb){ return new Execution(flow, data); });
    return async.map(execs, function(e, cb){ e.exec(cb); }, callback);
  } else {
    return new Execution(flow, data).exec(callback);
  }
}
github shutterstock / fnFlow / lib / fnFlow.js View on Github external
self._initialize = function _initialize(){
    if(self.parent) {
      if(!context_name) throw new errors.ArgumentNull('context_name');
    } else {
      if(args.length == 1) tasks = context_name, context_name = undefined;
    }

    self.context_name = context_name; 
    self.tasks = us.extend(self.tasks, tasks || {});

    self._initialize_tasks();
  }
github shutterstock / fnFlow / lib / task.js View on Github external
}
    if(!self.is_sync) fnArgs.push(cb);

    var fn = plan.fn;
    var receiver;
    if(typeof plan.fn != 'function') {
      var fnName = plan.fn.name;
      var receiverName = plan.fn.receiverName;
      try {
        receiver = evalMessages(results, receiverName, self.name);
      } catch(e) { 
        if(e.name == "FlowTaskArgumentNullError") e.message = "Not Found During Flow: " + self.tasks[self.name].toString(results, e.argumentName);
        return callback(e); 
      }
      if(!receiver) {
        var err = new errors.ArgumentNull(receiverName.join('.'));
        if(flow.tasks[receiverName[0]]) err.message = "Not Found: " + flow.tasks[receiverName[0]].toString(results, err.argumentName);
        return callback(err)
      }
      fn = receiver[fnName];
      if(!fn) return callback(new FlowTaskError(self.name, "Unknown symbol '" + fnName + "' must be either the name of a task, the name of data, or the name of a function on '" + receiverName + "'"));
      if(typeof fn != 'function') return callback(new FlowTaskError(self.name, "Not a function: " + (receiverName.length ? (receiverName.join('.') + ".") : '') + fnName));
    }

    try {
      var return_value = fn.apply(receiver, fnArgs);
      if(self.is_sync) cb(null, return_value);
    } catch(e){
      return callback(new FlowTaskError(self.name, "Error during execution of function.", e));
    }
  });
github shutterstock / fnFlow / lib / task.js View on Github external
Task.prototype.requires = function requires(task_names) {
  if(!task_names) throw new errors.ArgumentNull('task_names');
  if(typeof task_names == 'string') this._explicit_reqs.push(task_names);
  else if(task_names instanceof Array) Array.prototype.push.apply(this._explicit_reqs, task_names);
  return this;
}