How to use the common-errors.ArgumentError 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 pandawing / node-run-yo / lib / mv-promised.js View on Github external
return new Promise(function (resolve, reject) {
    if (!value) {
      reject(new errors.TypeError('requires value[source], value[dest]'));
      return;
    }
    // FIXME
    if ([value['source'], value['dest']].some(function (key) {
      return key === null || key === '' || key === '.' || key === '/';
    })) {
      reject(new errors.ArgumentError('input is not allowed'));
      return;
    }

    mv(value['source'], value['dest'], { mkdirp: true }, function (err) {
      if (err) {
        reject(err);
        return;
      }
      resolve();
    });
  });
};
github pandawing / node-run-yo / lib / app-compile-dir.js View on Github external
['input', 'packageName'].forEach(function (key) {
      if(!value.hasOwnProperty(key) || !value[key]) {
        reject(new errors.ArgumentNullError(key));
        return;
      }
    });
    var packageName = value['packageName'];
    var input = removeTrailingSeparator(value['input']);
    if (!isPackage(packageName)) {
      reject(new errors.ArgumentError(packageName + 'is not package'));
      return;
    }
    var split = path.normalize(input).split(path.sep);
    var inputLast = split[split.length - 1];
    if (inputLast === '..' || inputLast == '' || inputLast == '.') {
      reject(new errors.ArgumentError('input last does not allow (empty), .., .'));
      return;
    }

    resolve(path.join(inputLast, packageName));
  });
};
github pandawing / node-run-yo / lib / mkdir-in-temp.js View on Github external
return new Promise(function (resolve, reject) {
    if (!value) {
      reject(new errors.ArgumentNullError('value'));
      return;
    }
    ['dir'].forEach(function (key) {
      if(!value.hasOwnProperty(key) || !value[key]) {
        reject(new errors.ArgumentNullError(key));
        return;
      }
    });

    var targetDir = removeTrailingSlash(path.normalize(value['dir']));
    if (targetDir.split(path.sep).indexOf('..') !== -1) {
      reject(new errors.ArgumentError('dir has .. directory'));
      return;
    }

    tmp.setGracefulCleanup();

    tmp.dir({ keep: true, unsafeCleanup: true }, function (err, dirPath, cleanupCallback) {
      if (err) {
        reject(new errors.Error('tmp.dir', err));
        return;
      }

      var clearMethod = cleanupCallback;
      var targetPath = path.join(dirPath, targetDir);
      mkdirp(targetPath, function (err) {
        if (err) {
          reject(new errors.Error('mkdirp', err));
github pandawing / node-run-yo / lib / generator-name.js View on Github external
return new Promise(function (resolve, reject) {
    if (!value) {
      reject(new errors.TypeError('generator name must be string'));
      return;
    }
    if (!isPackage(value)) {
      reject(new errors.ArgumentError('this is not package name: ' + value));
      return;
    } else {
      if (isScopedPackage(value)) {
        var split = value.split('/');
        removeGeneratorPrefix(split[1], function (err, data) {
          if (err) {
            reject(err);
            return;
          }
          resolve(split[0] + '/' + data);
          return;
        });
      } else {
        removeGeneratorPrefix(value, function (err, data) {
          if (err) {
            reject(err);
github pandawing / node-run-yo / lib / pick-target.js View on Github external
module.exports = function (input, cb) {
  if (type(input) !== 'string') {
    cb(new errors.TypeError('input requires string'), null);
    return;
  }
  var split = removeTrailingSeparator(path.normalize(input)).split(path.sep);
  var inputLast = split[split.length - 1];
  if (['', '.', '..'].some(function (value) {
    return inputLast === value;
  })) {
    cb(new errors.ArgumentError('input is not allowed: ' + prettyFormat(inputLast)), null);
    return;
  }
  cb(null, inputLast);
};
github pandawing / node-run-yo / lib / app-compile-dir.js View on Github external
return new Promise(function (resolve, reject) {
    if (!value) {
      reject(new errors.ArgumentNullError('value'));
      return;
    }
    ['input', 'packageName'].forEach(function (key) {
      if(!value.hasOwnProperty(key) || !value[key]) {
        reject(new errors.ArgumentNullError(key));
        return;
      }
    });
    var packageName = value['packageName'];
    var input = removeTrailingSeparator(value['input']);
    if (!isPackage(packageName)) {
      reject(new errors.ArgumentError(packageName + 'is not package'));
      return;
    }
    var split = path.normalize(input).split(path.sep);
    var inputLast = split[split.length - 1];
    if (inputLast === '..' || inputLast == '' || inputLast == '.') {
      reject(new errors.ArgumentError('input last does not allow (empty), .., .'));
      return;
    }

    resolve(path.join(inputLast, packageName));
  });
};
github ubiq / shokku / src / server / services / jsonrpc.js View on Github external
try {
      const response = await web3[opts.network].safe[opts.method].apply(this, opts.params)
      return {
        id: opts.id || this.randomId(),
        jsonrpc: '2.0',
        result: response
      }
    } catch (err) {
      const errMsg = err.message.replace(/"/g, "'")
      l.error('JsonRpcService - method() / ', errMsg)
      let error
      if (errMsg.match(/^Returned error/)) {
        error = new errors.Error(err.message)
      } else if (errMsg.match(/^Invalid number of parameters/)) {
        error = new errors.ArgumentError('Invalid number of params used', err)
      } else if (errMsg.match(/^(?:CONNECTION ERROR|CONNECTION TIMEOUT|Provider not set or invalid)/)) {
        error = new errors.ConnectionError('Impossible to connect to node.', err)
      } else if (errMsg.match(/^Invalid JSON RPC response/)) {
        error = new errors.InvalidOperationError('Invalid JSON RPC response', err)
      } else {
        error = new errors.Error('Invalid JSON RPC response from node')
      }
      throw error
    }
  }
github pandawing / node-run-yo / lib / lnfs-promised.js View on Github external
module.exports = function (value) {
  if (!value) {
    return Promise.reject(new errors.TypeError('requires value[src], value[dest]'));
  }
  if(value['src'] === null || value['src'] === '' || value['src'] === '.' || value['src'] === '/') {
    return Promise.reject(new errors.ArgumentError('input is not allowed: ' + value['src']));
  }
  if(value['dest'] === null || value['dest'] === '' || value['dest'] === '.' || value['dest'] === '/') {
    return Promise.reject(new errors.ArgumentError('input is not allowed: ' + value['dest']));
  }
  return lnfs(value['src'], value['dest']);
};
github pandawing / node-run-yo / lib / remove-generator-prefix.js View on Github external
module.exports = function (prefixedGenerator, cb) {
  var matched = prefixedGenerator.match(/^generator-(.+)/);
  if (!matched || !matched[1]) {
    cb(new errors.ArgumentError('not match to generator: ' + prefixedGenerator), null);
    return;
  }
  cb(null, matched[1]);
};