3 function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
7 function createErrorType(code, message, Base) {
12 function getMessage(arg1, arg2, arg3) {
13 if (typeof message === 'string') {
16 return message(arg1, arg2, arg3);
23 _inheritsLoose(NodeError, _Base);
25 function NodeError(arg1, arg2, arg3) {
26 return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
32 NodeError.prototype.name = Base.name;
33 NodeError.prototype.code = code;
34 codes[code] = NodeError;
35 } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
38 function oneOf(expected, thing) {
39 if (Array.isArray(expected)) {
40 var len = expected.length;
41 expected = expected.map(function (i) {
46 return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
47 } else if (len === 2) {
48 return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
50 return "of ".concat(thing, " ").concat(expected[0]);
53 return "of ".concat(thing, " ").concat(String(expected));
55 } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
58 function startsWith(str, search, pos) {
59 return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
60 } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
63 function endsWith(str, search, this_len) {
64 if (this_len === undefined || this_len > str.length) {
65 this_len = str.length;
68 return str.substring(this_len - search.length, this_len) === search;
69 } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
72 function includes(str, search, start) {
73 if (typeof start !== 'number') {
77 if (start + search.length > str.length) {
80 return str.indexOf(search, start) !== -1;
84 createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
85 return 'The value "' + value + '" is invalid for option "' + name + '"';
87 createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
88 // determiner: 'must be' or 'must not be'
91 if (typeof expected === 'string' && startsWith(expected, 'not ')) {
92 determiner = 'must not be';
93 expected = expected.replace(/^not /, '');
95 determiner = 'must be';
100 if (endsWith(name, ' argument')) {
101 // For cases like 'first argument'
102 msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
104 var type = includes(name, '.') ? 'property' : 'argument';
105 msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
108 msg += ". Received type ".concat(typeof actual);
111 createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
112 createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
113 return 'The ' + name + ' method is not implemented';
115 createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
116 createErrorType('ERR_STREAM_DESTROYED', function (name) {
117 return 'Cannot call ' + name + ' after a stream was destroyed';
119 createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
120 createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
121 createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
122 createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
123 createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
124 return 'Unknown encoding: ' + arg;
126 createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
127 module.exports.codes = codes;