src/lib/errors.js
function createError(code, type, desc) {
	errors[code] = function (msg, meta) {
		const err = new type(msg);

		if (desc) {
			if (!meta) {
				meta = {};
			}
			meta.desc = desc;
		}

		return Object.defineProperties(err, {
			code: {
				configurable: true,
				enumerable: true,
				writable: true,
				value: `ERR_${code}`
			},
			meta: {
				configurable: true,
				value: meta || undefined,
				writable: true
			}
		});
	};

	Object.defineProperties(errors[code], {
		name: {
			configurable: true,
			value: code,
			writable: true
		},
		toString: {
			configurable: true,
			value: function toString() {
				return `ERR_${code}`;
			},
			writable: true
		}
	});
}
function createError(code, type, desc) {
	errors[code] = function (msg, meta) {
		const err = new type(msg);

		if (desc) {
			if (!meta) {
				meta = {};
			}
			meta.desc = desc;
		}

		return Object.defineProperties(err, {
			code: {
				configurable: true,
				enumerable: true,
				writable: true,
				value: `ERR_${code}`
			},
			meta: {
				configurable: true,
				value: meta || undefined,
				writable: true
			}
		});
	};

	Object.defineProperties(errors[code], {
		name: {
			configurable: true,
			value: code,
			writable: true
		},
		toString: {
			configurable: true,
			value: function toString() {
				return `ERR_${code}`;
			},
			writable: true
		}
	});
}
function createError ( code , type , desc ) { errors [ code ] = function ( msg , meta ) { const err = new type ( msg ) ; if ( desc ) { if ( ! meta ) { meta = { } ; } meta . desc = desc ; } return Object . defineProperties ( err , { code : { configurable : true , enumerable : true , writable : true , value : ` ${ code } ` } , meta : { configurable : true , value : meta || undefined , writable : true } } ) ; } ; Object . defineProperties ( errors [ code ] , { name : { configurable : true , value : code , writable : true } , toString : { configurable : true , value : function toString ( ) { return ` ${ code } ` ; } , writable : true } } ) ; }
Creates an the error object and populates the message, code, and metadata.

@param {String} code - The error code.
@param {Error|RangeError|TypeError} type - An instantiable error object.
@param {String} desc - A generic error description.
Creates an the error object and populates the message code and metadata .