1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var __extends = (this && this.__extends) || (function () {
|
8 | var extendStatics = function (d, b) {
|
9 | extendStatics = Object.setPrototypeOf ||
|
10 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
11 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
12 | return extendStatics(d, b);
|
13 | };
|
14 | return function (d, b) {
|
15 | extendStatics(d, b);
|
16 | function __() { this.constructor = d; }
|
17 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
18 | };
|
19 | })();
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | exports.E = exports.AssertionError = exports.message = exports.RangeError = exports.TypeError = exports.Error = void 0;
|
22 | var assert = require("assert");
|
23 | var util = require("util");
|
24 | var kCode = typeof Symbol === 'undefined' ? '_kCode' : Symbol('code');
|
25 | var messages = {};
|
26 | function makeNodeError(Base) {
|
27 | return (function (_super) {
|
28 | __extends(NodeError, _super);
|
29 | function NodeError(key) {
|
30 | var args = [];
|
31 | for (var _i = 1; _i < arguments.length; _i++) {
|
32 | args[_i - 1] = arguments[_i];
|
33 | }
|
34 | var _this = _super.call(this, message(key, args)) || this;
|
35 | _this.code = key;
|
36 | _this[kCode] = key;
|
37 | _this.name = _super.prototype.name + " [" + _this[kCode] + "]";
|
38 | return _this;
|
39 | }
|
40 | return NodeError;
|
41 | }(Base));
|
42 | }
|
43 | var AssertionError = (function (_super) {
|
44 | __extends(AssertionError, _super);
|
45 | function AssertionError(options) {
|
46 | var _this = this;
|
47 | if (typeof options !== 'object' || options === null) {
|
48 | throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
|
49 | }
|
50 | if (options.message) {
|
51 | _this = _super.call(this, options.message) || this;
|
52 | }
|
53 | else {
|
54 | _this = _super.call(this, util.inspect(options.actual).slice(0, 128) + " " +
|
55 | (options.operator + " " + util.inspect(options.expected).slice(0, 128))) || this;
|
56 | }
|
57 | _this.generatedMessage = !options.message;
|
58 | _this.name = 'AssertionError [ERR_ASSERTION]';
|
59 | _this.code = 'ERR_ASSERTION';
|
60 | _this.actual = options.actual;
|
61 | _this.expected = options.expected;
|
62 | _this.operator = options.operator;
|
63 | exports.Error.captureStackTrace(_this, options.stackStartFunction);
|
64 | return _this;
|
65 | }
|
66 | return AssertionError;
|
67 | }(global.Error));
|
68 | exports.AssertionError = AssertionError;
|
69 | function message(key, args) {
|
70 | assert.strictEqual(typeof key, 'string');
|
71 |
|
72 | var msg = messages[key];
|
73 | assert(msg, "An invalid error message key was used: " + key + ".");
|
74 | var fmt;
|
75 | if (typeof msg === 'function') {
|
76 | fmt = msg;
|
77 | }
|
78 | else {
|
79 | fmt = util.format;
|
80 | if (args === undefined || args.length === 0)
|
81 | return msg;
|
82 | args.unshift(msg);
|
83 | }
|
84 | return String(fmt.apply(null, args));
|
85 | }
|
86 | exports.message = message;
|
87 |
|
88 |
|
89 | function E(sym, val) {
|
90 | messages[sym] = typeof val === 'function' ? val : String(val);
|
91 | }
|
92 | exports.E = E;
|
93 | exports.Error = makeNodeError(global.Error);
|
94 | exports.TypeError = makeNodeError(global.TypeError);
|
95 | exports.RangeError = makeNodeError(global.RangeError);
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | E('ERR_ARG_NOT_ITERABLE', '%s must be iterable');
|
110 | E('ERR_ASSERTION', '%s');
|
111 | E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds);
|
112 | E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received');
|
113 | E('ERR_CONSOLE_WRITABLE_STREAM', 'Console expects a writable stream instance for %s');
|
114 | E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s');
|
115 | E('ERR_DNS_SET_SERVERS_FAILED', function (err, servers) { return "c-ares failed to set servers: \"" + err + "\" [" + servers + "]"; });
|
116 | E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value');
|
117 | E('ERR_ENCODING_NOT_SUPPORTED', function (enc) { return "The \"" + enc + "\" encoding is not supported"; });
|
118 | E('ERR_ENCODING_INVALID_ENCODED_DATA', function (enc) { return "The encoded data was not valid for encoding " + enc; });
|
119 | E('ERR_HTTP_HEADERS_SENT', 'Cannot render headers after they are sent to the client');
|
120 | E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s');
|
121 | E('ERR_HTTP_TRAILER_INVALID', 'Trailers are invalid with this transfer encoding');
|
122 | E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
|
123 | E('ERR_INVALID_ARG_TYPE', invalidArgType);
|
124 | E('ERR_INVALID_ARRAY_LENGTH', function (name, len, actual) {
|
125 | assert.strictEqual(typeof actual, 'number');
|
126 | return "The array \"" + name + "\" (length " + actual + ") must be of length " + len + ".";
|
127 | });
|
128 | E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s');
|
129 | E('ERR_INVALID_CALLBACK', 'Callback must be a function');
|
130 | E('ERR_INVALID_CHAR', 'Invalid character in %s');
|
131 | E('ERR_INVALID_CURSOR_POS', 'Cannot set cursor row without setting its column');
|
132 | E('ERR_INVALID_FD', '"fd" must be a positive integer: %s');
|
133 | E('ERR_INVALID_FILE_URL_HOST', 'File URL host must be "localhost" or empty on %s');
|
134 | E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s');
|
135 | E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent');
|
136 | E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s');
|
137 | E('ERR_INVALID_OPT_VALUE', function (name, value) {
|
138 | return "The value \"" + String(value) + "\" is invalid for option \"" + name + "\"";
|
139 | });
|
140 | E('ERR_INVALID_OPT_VALUE_ENCODING', function (value) { return "The value \"" + String(value) + "\" is invalid for option \"encoding\""; });
|
141 | E('ERR_INVALID_REPL_EVAL_CONFIG', 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL');
|
142 | E('ERR_INVALID_SYNC_FORK_INPUT', 'Asynchronous forks do not support Buffer, Uint8Array or string input: %s');
|
143 | E('ERR_INVALID_THIS', 'Value of "this" must be of type %s');
|
144 | E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple');
|
145 | E('ERR_INVALID_URL', 'Invalid URL: %s');
|
146 | E('ERR_INVALID_URL_SCHEME', function (expected) { return "The URL must be " + oneOf(expected, 'scheme'); });
|
147 | E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed');
|
148 | E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected');
|
149 | E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe');
|
150 | E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
|
151 | E('ERR_MISSING_ARGS', missingArgs);
|
152 | E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
|
153 | E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function');
|
154 | E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
|
155 | E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
|
156 | E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
|
157 | E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
|
158 | E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound');
|
159 | E('ERR_SOCKET_BAD_PORT', 'Port should be > 0 and < 65536');
|
160 | E('ERR_SOCKET_BAD_TYPE', 'Bad socket type specified. Valid types are: udp4, udp6');
|
161 | E('ERR_SOCKET_CANNOT_SEND', 'Unable to send data');
|
162 | E('ERR_SOCKET_CLOSED', 'Socket is closed');
|
163 | E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running');
|
164 | E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
|
165 | E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
|
166 | E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode');
|
167 | E('ERR_TLS_CERT_ALTNAME_INVALID', "Hostname/IP does not match certificate's altnames: %s");
|
168 | E('ERR_TLS_DH_PARAM_SIZE', function (size) { return "DH parameter size " + size + " is less than 2048"; });
|
169 | E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout');
|
170 | E('ERR_TLS_RENEGOTIATION_FAILED', 'Failed to renegotiate');
|
171 | E('ERR_TLS_REQUIRED_SERVER_NAME', '"servername" is required parameter for Server.addContext');
|
172 | E('ERR_TLS_SESSION_ATTACK', 'TSL session renegotiation attack detected');
|
173 | E('ERR_TRANSFORM_ALREADY_TRANSFORMING', 'Calling transform done when still transforming');
|
174 | E('ERR_TRANSFORM_WITH_LENGTH_0', 'Calling transform done when writableState.length != 0');
|
175 | E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s');
|
176 | E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s');
|
177 | E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
|
178 | E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
|
179 | E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + 'See https://github.com/nodejs/node/wiki/Intl');
|
180 | function invalidArgType(name, expected, actual) {
|
181 | assert(name, 'name is required');
|
182 |
|
183 | var determiner;
|
184 | if (expected.includes('not ')) {
|
185 | determiner = 'must not be';
|
186 | expected = expected.split('not ')[1];
|
187 | }
|
188 | else {
|
189 | determiner = 'must be';
|
190 | }
|
191 | var msg;
|
192 | if (Array.isArray(name)) {
|
193 | var names = name.map(function (val) { return "\"" + val + "\""; }).join(', ');
|
194 | msg = "The " + names + " arguments " + determiner + " " + oneOf(expected, 'type');
|
195 | }
|
196 | else if (name.includes(' argument')) {
|
197 |
|
198 | msg = "The " + name + " " + determiner + " " + oneOf(expected, 'type');
|
199 | }
|
200 | else {
|
201 | var type = name.includes('.') ? 'property' : 'argument';
|
202 | msg = "The \"" + name + "\" " + type + " " + determiner + " " + oneOf(expected, 'type');
|
203 | }
|
204 |
|
205 | if (arguments.length >= 3) {
|
206 | msg += ". Received type " + (actual !== null ? typeof actual : 'null');
|
207 | }
|
208 | return msg;
|
209 | }
|
210 | function missingArgs() {
|
211 | var args = [];
|
212 | for (var _i = 0; _i < arguments.length; _i++) {
|
213 | args[_i] = arguments[_i];
|
214 | }
|
215 | assert(args.length > 0, 'At least one arg needs to be specified');
|
216 | var msg = 'The ';
|
217 | var len = args.length;
|
218 | args = args.map(function (a) { return "\"" + a + "\""; });
|
219 | switch (len) {
|
220 | case 1:
|
221 | msg += args[0] + " argument";
|
222 | break;
|
223 | case 2:
|
224 | msg += args[0] + " and " + args[1] + " arguments";
|
225 | break;
|
226 | default:
|
227 | msg += args.slice(0, len - 1).join(', ');
|
228 | msg += ", and " + args[len - 1] + " arguments";
|
229 | break;
|
230 | }
|
231 | return msg + " must be specified";
|
232 | }
|
233 | function oneOf(expected, thing) {
|
234 | assert(expected, 'expected is required');
|
235 | assert(typeof thing === 'string', 'thing is required');
|
236 | if (Array.isArray(expected)) {
|
237 | var len = expected.length;
|
238 | assert(len > 0, 'At least one expected value needs to be specified');
|
239 |
|
240 | expected = expected.map(function (i) { return String(i); });
|
241 | if (len > 2) {
|
242 | return "one of " + thing + " " + expected.slice(0, len - 1).join(', ') + ", or " + expected[len - 1];
|
243 | }
|
244 | else if (len === 2) {
|
245 | return "one of " + thing + " " + expected[0] + " or " + expected[1];
|
246 | }
|
247 | else {
|
248 | return "of " + thing + " " + expected[0];
|
249 | }
|
250 | }
|
251 | else {
|
252 | return "of " + thing + " " + String(expected);
|
253 | }
|
254 | }
|
255 | function bufferOutOfBounds(name, isWriting) {
|
256 | if (isWriting) {
|
257 | return 'Attempt to write outside buffer bounds';
|
258 | }
|
259 | else {
|
260 | return "\"" + name + "\" is outside of buffer bounds";
|
261 | }
|
262 | }
|