How to use the error.BadOptionsError function in error

To help you get started, we’ve selected a few error 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 rapid7 / le_node / src / node_modules / logger.js View on Github external
if (!_.isObject(opts))
			throw new BadOptionsError(opts, text.optionsNotObj(typeof opts));

		if (_.isUndefined(opts.token))
			throw new BadOptionsError(opts, text.noToken());

		if (!_.isString(opts.token) || !tokenPattern.test(opts.token))
			throw new BadOptionsError(opts, text.invalidToken(opts.token));

		// Log method aliases

		this[$levels] = levelUtil.normalize(opts);

		for (const lvlName of this.levels) {
			if (lvlName in this)
				throw new BadOptionsError(opts, text.levelConflict(lvlName));

			Object.defineProperty(this, lvlName, {
				enumerable: true,
				writable: false,
				value() {
					this.log.apply(this, [lvlName, ...arguments]);
				}
			});
		}

		const bufferSizeConfig = opts.bufferSize || defaults.bufferSize;

		this.ringBuffer = new RingBuffer(bufferSizeConfig);

		// Other permanent options
github rapid7 / le_node / src / node_modules / logger.js View on Github external
constructor(opts) {
		super({
			objectMode: true,
			highWaterMark: 0
		});

		// Sanity checks

		if (_.isUndefined(opts))
			throw new BadOptionsError(opts, text.noOptions());

		if (!_.isObject(opts))
			throw new BadOptionsError(opts, text.optionsNotObj(typeof opts));

		if (_.isUndefined(opts.token))
			throw new BadOptionsError(opts, text.noToken());

		if (!_.isString(opts.token) || !tokenPattern.test(opts.token))
			throw new BadOptionsError(opts, text.invalidToken(opts.token));

		// Log method aliases

		this[$levels] = levelUtil.normalize(opts);

		for (const lvlName of this.levels) {
			if (lvlName in this)
				throw new BadOptionsError(opts, text.levelConflict(lvlName));

			Object.defineProperty(this, lvlName, {
github rapid7 / le_node / src / node_modules / logger.js View on Github external
constructor(opts) {
		super({
			objectMode: true,
			highWaterMark: 0
		});

		// Sanity checks

		if (_.isUndefined(opts))
			throw new BadOptionsError(opts, text.noOptions());

		if (!_.isObject(opts))
			throw new BadOptionsError(opts, text.optionsNotObj(typeof opts));

		if (_.isUndefined(opts.token))
			throw new BadOptionsError(opts, text.noToken());

		if (!_.isString(opts.token) || !tokenPattern.test(opts.token))
			throw new BadOptionsError(opts, text.invalidToken(opts.token));

		// Log method aliases

		this[$levels] = levelUtil.normalize(opts);

		for (const lvlName of this.levels) {
			if (lvlName in this)
github rapid7 / le_node / src / node_modules / logger.js View on Github external
constructor(opts) {
		super({
			objectMode: true,
			highWaterMark: 0
		});

		// Sanity checks

		if (_.isUndefined(opts))
			throw new BadOptionsError(opts, text.noOptions());

		if (!_.isObject(opts))
			throw new BadOptionsError(opts, text.optionsNotObj(typeof opts));

		if (_.isUndefined(opts.token))
			throw new BadOptionsError(opts, text.noToken());

		if (!_.isString(opts.token) || !tokenPattern.test(opts.token))
			throw new BadOptionsError(opts, text.invalidToken(opts.token));

		// Log method aliases

		this[$levels] = levelUtil.normalize(opts);

		for (const lvlName of this.levels) {
			if (lvlName in this)
				throw new BadOptionsError(opts, text.levelConflict(lvlName));

			Object.defineProperty(this, lvlName, {
				enumerable: true,
				writable: false,
				value() {
github rapid7 / le_node / src / node_modules / levels.js View on Github external
export const normalize = (opts) => {

	let custom = opts.levels;

	if (!_.isUndefined(custom) && !_.isNull(custom) && !_.isObject(custom))
		throw new BadOptionsError(opts, text.levelsNotObj(typeof custom));

	if (!custom)
		return defaults.levels.slice();

	custom = _.isArray(custom) ? normArr(custom, opts) : normObj(custom, opts);

	const levels = defaults.levels.map((lvl, i) => custom[i] || lvl);

	const duplicates =
		_(levels).countBy().pick(count => count > 1).keys().value();

	if (duplicates.length)
		throw new BadOptionsError(opts, text.duplicateLevels(duplicates));

	return levels;
};
github rapid7 / le_node / src / node_modules / levels.js View on Github external
const normArr = (arr, opts) => {
	if (arr.length > 8)
		throw new BadOptionsError(opts, text.tooManyLevels(arr.length));

	return arr.map(val => {
		if (val && _.isString(val)) return val;
		if (_.isNumber(val) && isFinite(val)) return val.toString();
		if (_.isNull(val) || _.isUndefined(val)) return;

		throw new BadOptionsError(opts, text.levelNotString(val));
	});
};
github rapid7 / le_node / src / node_modules / levels.js View on Github external
const normObj = (obj, opts) => {
	const lvlNums = _.values(obj);

	for (const num of lvlNums) {
		if (!isNumberValid(num))
			throw new BadOptionsError(opts, text.invalidLevelNum(num));
	}

	const duplicates =
		_(obj).countBy().pick(lvl => lvl > 1).keys().value();

	if (duplicates.length)
		throw new BadOptionsError(opts, text.duplicateLevelNums(duplicates));

	return _.reduce(obj, (arr, i, name) => {
		arr[i] = name;
		return arr;
	}, []);
};
github rapid7 / le_node / src / node_modules / levels.js View on Github external
const normObj = (obj, opts) => {
	const lvlNums = _.values(obj);

	for (const num of lvlNums) {
		if (!isNumberValid(num))
			throw new BadOptionsError(opts, text.invalidLevelNum(num));
	}

	const duplicates =
		_(obj).countBy().pick(lvl => lvl > 1).keys().value();

	if (duplicates.length)
		throw new BadOptionsError(opts, text.duplicateLevelNums(duplicates));

	return _.reduce(obj, (arr, i, name) => {
		arr[i] = name;
		return arr;
	}, []);
};
github rapid7 / le_node / src / node_modules / levels.js View on Github external
return arr.map(val => {
		if (val && _.isString(val)) return val;
		if (_.isNumber(val) && isFinite(val)) return val.toString();
		if (_.isNull(val) || _.isUndefined(val)) return;

		throw new BadOptionsError(opts, text.levelNotString(val));
	});
};
github rapid7 / le_node / src / node_modules / levels.js View on Github external
if (!_.isUndefined(custom) && !_.isNull(custom) && !_.isObject(custom))
		throw new BadOptionsError(opts, text.levelsNotObj(typeof custom));

	if (!custom)
		return defaults.levels.slice();

	custom = _.isArray(custom) ? normArr(custom, opts) : normObj(custom, opts);

	const levels = defaults.levels.map((lvl, i) => custom[i] || lvl);

	const duplicates =
		_(levels).countBy().pick(count => count > 1).keys().value();

	if (duplicates.length)
		throw new BadOptionsError(opts, text.duplicateLevels(duplicates));

	return levels;
};