1/* eslint node-core/documented-errors: "error" */ 2/* eslint node-core/alphabetize-errors: "error" */ 3/* eslint node-core/prefer-util-format-errors: "error" */ 4 5'use strict'; 6 7// The whole point behind this internal module is to allow Node.js to no 8// longer be forced to treat every error message change as a semver-major 9// change. The NodeError classes here all expose a `code` property whose 10// value statically and permanently identifies the error. While the error 11// message may change, the code should not. 12 13const { 14 ArrayIsArray, 15 Error, 16 ErrorPrototypeToString, 17 JSONStringify, 18 Map, 19 MathAbs, 20 MathMax, 21 NumberIsInteger, 22 ObjectDefineProperty, 23 ObjectKeys, 24 StringPrototypeStartsWith, 25 Symbol, 26 SymbolFor, 27 WeakMap, 28} = primordials; 29 30const isWindows = process.platform === 'win32'; 31 32const messages = new Map(); 33const codes = {}; 34 35const classRegExp = /^([A-Z][a-z0-9]*)+$/; 36// Sorted by a rough estimate on most frequently used entries. 37const kTypes = [ 38 'string', 39 'function', 40 'number', 41 'object', 42 // Accept 'Function' and 'Object' as alternative to the lower cased version. 43 'Function', 44 'Object', 45 'boolean', 46 'bigint', 47 'symbol' 48]; 49 50const { kMaxLength } = internalBinding('buffer'); 51 52const MainContextError = Error; 53const overrideStackTrace = new WeakMap(); 54const kNoOverride = Symbol('kNoOverride'); 55const prepareStackTrace = (globalThis, error, trace) => { 56 // API for node internals to override error stack formatting 57 // without interfering with userland code. 58 if (overrideStackTrace.has(error)) { 59 const f = overrideStackTrace.get(error); 60 overrideStackTrace.delete(error); 61 return f(error, trace); 62 } 63 64 const globalOverride = 65 maybeOverridePrepareStackTrace(globalThis, error, trace); 66 if (globalOverride !== kNoOverride) return globalOverride; 67 68 // Normal error formatting: 69 // 70 // Error: Message 71 // at function (file) 72 // at file 73 const errorString = ErrorPrototypeToString(error); 74 if (trace.length === 0) { 75 return errorString; 76 } 77 return `${errorString}\n at ${trace.join('\n at ')}`; 78}; 79 80const maybeOverridePrepareStackTrace = (globalThis, error, trace) => { 81 // Polyfill of V8's Error.prepareStackTrace API. 82 // https://crbug.com/v8/7848 83 // `globalThis` is the global that contains the constructor which 84 // created `error`. 85 if (typeof globalThis.Error.prepareStackTrace === 'function') { 86 return globalThis.Error.prepareStackTrace(error, trace); 87 } 88 // We still have legacy usage that depends on the main context's `Error` 89 // being used, even when the error is from a different context. 90 // TODO(devsnek): evaluate if this can be eventually deprecated/removed. 91 if (typeof MainContextError.prepareStackTrace === 'function') { 92 return MainContextError.prepareStackTrace(error, trace); 93 } 94 95 return kNoOverride; 96}; 97 98let excludedStackFn; 99 100// Lazily loaded 101let util; 102let assert; 103 104let internalUtil = null; 105function lazyInternalUtil() { 106 if (!internalUtil) { 107 internalUtil = require('internal/util'); 108 } 109 return internalUtil; 110} 111 112let internalUtilInspect = null; 113function lazyInternalUtilInspect() { 114 if (!internalUtilInspect) { 115 internalUtilInspect = require('internal/util/inspect'); 116 } 117 return internalUtilInspect; 118} 119 120let buffer; 121function lazyBuffer() { 122 if (buffer === undefined) 123 buffer = require('buffer').Buffer; 124 return buffer; 125} 126 127// A specialized Error that includes an additional info property with 128// additional information about the error condition. 129// It has the properties present in a UVException but with a custom error 130// message followed by the uv error code and uv error message. 131// It also has its own error code with the original uv error context put into 132// `err.info`. 133// The context passed into this error must have .code, .syscall and .message, 134// and may have .path and .dest. 135class SystemError extends Error { 136 constructor(key, context) { 137 if (excludedStackFn === undefined) { 138 super(); 139 } else { 140 const limit = Error.stackTraceLimit; 141 Error.stackTraceLimit = 0; 142 super(); 143 // Reset the limit and setting the name property. 144 Error.stackTraceLimit = limit; 145 } 146 const prefix = getMessage(key, [], this); 147 let message = `${prefix}: ${context.syscall} returned ` + 148 `${context.code} (${context.message})`; 149 150 if (context.path !== undefined) 151 message += ` ${context.path}`; 152 if (context.dest !== undefined) 153 message += ` => ${context.dest}`; 154 155 ObjectDefineProperty(this, 'message', { 156 value: message, 157 enumerable: false, 158 writable: true, 159 configurable: true 160 }); 161 addCodeToName(this, 'SystemError', key); 162 163 this.code = key; 164 165 ObjectDefineProperty(this, 'info', { 166 value: context, 167 enumerable: true, 168 configurable: true, 169 writable: false 170 }); 171 172 ObjectDefineProperty(this, 'errno', { 173 get() { 174 return context.errno; 175 }, 176 set: (value) => { 177 context.errno = value; 178 }, 179 enumerable: true, 180 configurable: true 181 }); 182 183 ObjectDefineProperty(this, 'syscall', { 184 get() { 185 return context.syscall; 186 }, 187 set: (value) => { 188 context.syscall = value; 189 }, 190 enumerable: true, 191 configurable: true 192 }); 193 194 if (context.path !== undefined) { 195 // TODO(BridgeAR): Investigate why and when the `.toString()` was 196 // introduced. The `path` and `dest` properties in the context seem to 197 // always be of type string. We should probably just remove the 198 // `.toString()` and `Buffer.from()` operations and set the value on the 199 // context as the user did. 200 ObjectDefineProperty(this, 'path', { 201 get() { 202 return context.path != null ? 203 context.path.toString() : context.path; 204 }, 205 set: (value) => { 206 context.path = value ? 207 lazyBuffer().from(value.toString()) : undefined; 208 }, 209 enumerable: true, 210 configurable: true 211 }); 212 } 213 214 if (context.dest !== undefined) { 215 ObjectDefineProperty(this, 'dest', { 216 get() { 217 return context.dest != null ? 218 context.dest.toString() : context.dest; 219 }, 220 set: (value) => { 221 context.dest = value ? 222 lazyBuffer().from(value.toString()) : undefined; 223 }, 224 enumerable: true, 225 configurable: true 226 }); 227 } 228 } 229 230 toString() { 231 return `${this.name} [${this.code}]: ${this.message}`; 232 } 233 234 [SymbolFor('nodejs.util.inspect.custom')](recurseTimes, ctx) { 235 return lazyInternalUtilInspect().inspect(this, { 236 ...ctx, 237 getters: true, 238 customInspect: false 239 }); 240 } 241} 242 243function makeSystemErrorWithCode(key) { 244 return class NodeError extends SystemError { 245 constructor(ctx) { 246 super(key, ctx); 247 } 248 }; 249} 250 251function makeNodeErrorWithCode(Base, key) { 252 return class NodeError extends Base { 253 constructor(...args) { 254 if (excludedStackFn === undefined) { 255 super(); 256 } else { 257 const limit = Error.stackTraceLimit; 258 Error.stackTraceLimit = 0; 259 super(); 260 // Reset the limit and setting the name property. 261 Error.stackTraceLimit = limit; 262 } 263 const message = getMessage(key, args, this); 264 ObjectDefineProperty(this, 'message', { 265 value: message, 266 enumerable: false, 267 writable: true, 268 configurable: true 269 }); 270 addCodeToName(this, super.name, key); 271 this.code = key; 272 } 273 274 toString() { 275 return `${this.name} [${key}]: ${this.message}`; 276 } 277 }; 278} 279 280// This function removes unnecessary frames from Node.js core errors. 281function hideStackFrames(fn) { 282 return function hidden(...args) { 283 // Make sure the most outer `hideStackFrames()` function is used. 284 let setStackFn = false; 285 if (excludedStackFn === undefined) { 286 excludedStackFn = hidden; 287 setStackFn = true; 288 } 289 try { 290 return fn(...args); 291 } finally { 292 if (setStackFn === true) { 293 excludedStackFn = undefined; 294 } 295 } 296 }; 297} 298 299function addCodeToName(err, name, code) { 300 // Set the stack 301 if (excludedStackFn !== undefined) { 302 // eslint-disable-next-line no-restricted-syntax 303 Error.captureStackTrace(err, excludedStackFn); 304 } 305 // Add the error code to the name to include it in the stack trace. 306 err.name = `${name} [${code}]`; 307 // Access the stack to generate the error message including the error code 308 // from the name. 309 err.stack; 310 // Reset the name to the actual name. 311 if (name === 'SystemError') { 312 ObjectDefineProperty(err, 'name', { 313 value: name, 314 enumerable: false, 315 writable: true, 316 configurable: true 317 }); 318 } else { 319 delete err.name; 320 } 321} 322 323// Utility function for registering the error codes. Only used here. Exported 324// *only* to allow for testing. 325function E(sym, val, def, ...otherClasses) { 326 // Special case for SystemError that formats the error message differently 327 // The SystemErrors only have SystemError as their base classes. 328 messages.set(sym, val); 329 if (def === SystemError) { 330 def = makeSystemErrorWithCode(sym); 331 } else { 332 def = makeNodeErrorWithCode(def, sym); 333 } 334 335 if (otherClasses.length !== 0) { 336 otherClasses.forEach((clazz) => { 337 def[clazz.name] = makeNodeErrorWithCode(clazz, sym); 338 }); 339 } 340 codes[sym] = def; 341} 342 343function getMessage(key, args, self) { 344 const msg = messages.get(key); 345 346 if (assert === undefined) assert = require('internal/assert'); 347 348 if (typeof msg === 'function') { 349 assert( 350 msg.length <= args.length, // Default options do not count. 351 `Code: ${key}; The provided arguments length (${args.length}) does not ` + 352 `match the required ones (${msg.length}).` 353 ); 354 return msg.apply(self, args); 355 } 356 357 const expectedLength = (msg.match(/%[dfijoOs]/g) || []).length; 358 assert( 359 expectedLength === args.length, 360 `Code: ${key}; The provided arguments length (${args.length}) does not ` + 361 `match the required ones (${expectedLength}).` 362 ); 363 if (args.length === 0) 364 return msg; 365 366 args.unshift(msg); 367 return lazyInternalUtilInspect().format.apply(null, args); 368} 369 370let uvBinding; 371 372function lazyUv() { 373 if (!uvBinding) { 374 uvBinding = internalBinding('uv'); 375 } 376 return uvBinding; 377} 378 379const uvUnmappedError = ['UNKNOWN', 'unknown error']; 380 381function uvErrmapGet(name) { 382 uvBinding = lazyUv(); 383 if (!uvBinding.errmap) { 384 uvBinding.errmap = uvBinding.getErrorMap(); 385 } 386 return uvBinding.errmap.get(name); 387} 388 389 390/** 391 * This creates an error compatible with errors produced in the C++ 392 * function UVException using a context object with data assembled in C++. 393 * The goal is to migrate them to ERR_* errors later when compatibility is 394 * not a concern. 395 * 396 * @param {Object} ctx 397 * @returns {Error} 398 */ 399function uvException(ctx) { 400 const [ code, uvmsg ] = uvErrmapGet(ctx.errno) || uvUnmappedError; 401 let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`; 402 403 let path; 404 let dest; 405 if (ctx.path) { 406 path = ctx.path.toString(); 407 message += ` '${path}'`; 408 } 409 if (ctx.dest) { 410 dest = ctx.dest.toString(); 411 message += ` -> '${dest}'`; 412 } 413 414 // Reducing the limit improves the performance significantly. We do not loose 415 // the stack frames due to the `captureStackTrace()` function that is called 416 // later. 417 const tmpLimit = Error.stackTraceLimit; 418 Error.stackTraceLimit = 0; 419 // Pass the message to the constructor instead of setting it on the object 420 // to make sure it is the same as the one created in C++ 421 // eslint-disable-next-line no-restricted-syntax 422 const err = new Error(message); 423 Error.stackTraceLimit = tmpLimit; 424 425 for (const prop of ObjectKeys(ctx)) { 426 if (prop === 'message' || prop === 'path' || prop === 'dest') { 427 continue; 428 } 429 err[prop] = ctx[prop]; 430 } 431 432 err.code = code; 433 if (path) { 434 err.path = path; 435 } 436 if (dest) { 437 err.dest = dest; 438 } 439 440 // eslint-disable-next-line no-restricted-syntax 441 Error.captureStackTrace(err, excludedStackFn || uvException); 442 return err; 443} 444 445/** 446 * This creates an error compatible with errors produced in the C++ 447 * This function should replace the deprecated 448 * `exceptionWithHostPort()` function. 449 * 450 * @param {number} err - A libuv error number 451 * @param {string} syscall 452 * @param {string} address 453 * @param {number} [port] 454 * @returns {Error} 455 */ 456function uvExceptionWithHostPort(err, syscall, address, port) { 457 const [ code, uvmsg ] = uvErrmapGet(err) || uvUnmappedError; 458 const message = `${syscall} ${code}: ${uvmsg}`; 459 let details = ''; 460 461 if (port && port > 0) { 462 details = ` ${address}:${port}`; 463 } else if (address) { 464 details = ` ${address}`; 465 } 466 467 // Reducing the limit improves the performance significantly. We do not loose 468 // the stack frames due to the `captureStackTrace()` function that is called 469 // later. 470 const tmpLimit = Error.stackTraceLimit; 471 Error.stackTraceLimit = 0; 472 // eslint-disable-next-line no-restricted-syntax 473 const ex = new Error(`${message}${details}`); 474 Error.stackTraceLimit = tmpLimit; 475 ex.code = code; 476 ex.errno = code; 477 ex.syscall = syscall; 478 ex.address = address; 479 if (port) { 480 ex.port = port; 481 } 482 483 // eslint-disable-next-line no-restricted-syntax 484 Error.captureStackTrace(ex, excludedStackFn || uvExceptionWithHostPort); 485 return ex; 486} 487 488/** 489 * This used to be util._errnoException(). 490 * 491 * @param {number} err - A libuv error number 492 * @param {string} syscall 493 * @param {string} [original] 494 * @returns {Error} 495 */ 496function errnoException(err, syscall, original) { 497 // TODO(joyeecheung): We have to use the type-checked 498 // getSystemErrorName(err) to guard against invalid arguments from users. 499 // This can be replaced with [ code ] = errmap.get(err) when this method 500 // is no longer exposed to user land. 501 if (util === undefined) util = require('util'); 502 const code = util.getSystemErrorName(err); 503 const message = original ? 504 `${syscall} ${code} ${original}` : `${syscall} ${code}`; 505 506 // eslint-disable-next-line no-restricted-syntax 507 const ex = new Error(message); 508 // TODO(joyeecheung): errno is supposed to err, like in uvException 509 ex.code = ex.errno = code; 510 ex.syscall = syscall; 511 512 // eslint-disable-next-line no-restricted-syntax 513 Error.captureStackTrace(ex, excludedStackFn || errnoException); 514 return ex; 515} 516 517/** 518 * Deprecated, new function is `uvExceptionWithHostPort()` 519 * New function added the error description directly 520 * from C++. this method for backwards compatibility 521 * @param {number} err - A libuv error number 522 * @param {string} syscall 523 * @param {string} address 524 * @param {number} [port] 525 * @param {string} [additional] 526 * @returns {Error} 527 */ 528function exceptionWithHostPort(err, syscall, address, port, additional) { 529 // TODO(joyeecheung): We have to use the type-checked 530 // getSystemErrorName(err) to guard against invalid arguments from users. 531 // This can be replaced with [ code ] = errmap.get(err) when this method 532 // is no longer exposed to user land. 533 if (util === undefined) util = require('util'); 534 const code = util.getSystemErrorName(err); 535 let details = ''; 536 if (port && port > 0) { 537 details = ` ${address}:${port}`; 538 } else if (address) { 539 details = ` ${address}`; 540 } 541 if (additional) { 542 details += ` - Local (${additional})`; 543 } 544 545 // Reducing the limit improves the performance significantly. We do not loose 546 // the stack frames due to the `captureStackTrace()` function that is called 547 // later. 548 const tmpLimit = Error.stackTraceLimit; 549 Error.stackTraceLimit = 0; 550 // eslint-disable-next-line no-restricted-syntax 551 const ex = new Error(`${syscall} ${code}${details}`); 552 // TODO(joyeecheung): errno is supposed to err, like in uvException 553 Error.stackTraceLimit = tmpLimit; 554 ex.code = ex.errno = code; 555 ex.syscall = syscall; 556 ex.address = address; 557 if (port) { 558 ex.port = port; 559 } 560 561 // eslint-disable-next-line no-restricted-syntax 562 Error.captureStackTrace(ex, excludedStackFn || exceptionWithHostPort); 563 return ex; 564} 565 566/** 567 * @param {number|string} code - A libuv error number or a c-ares error code 568 * @param {string} syscall 569 * @param {string} [hostname] 570 * @returns {Error} 571 */ 572function dnsException(code, syscall, hostname) { 573 // If `code` is of type number, it is a libuv error number, else it is a 574 // c-ares error code. 575 if (typeof code === 'number') { 576 // ENOTFOUND is not a proper POSIX error, but this error has been in place 577 // long enough that it's not practical to remove it. 578 if (code === lazyUv().UV_EAI_NODATA || code === lazyUv().UV_EAI_NONAME) { 579 code = 'ENOTFOUND'; // Fabricated error name. 580 } else { 581 code = lazyInternalUtil().getSystemErrorName(code); 582 } 583 } 584 const message = `${syscall} ${code}${hostname ? ` ${hostname}` : ''}`; 585 // Reducing the limit improves the performance significantly. We do not loose 586 // the stack frames due to the `captureStackTrace()` function that is called 587 // later. 588 const tmpLimit = Error.stackTraceLimit; 589 Error.stackTraceLimit = 0; 590 // eslint-disable-next-line no-restricted-syntax 591 const ex = new Error(message); 592 // TODO(joyeecheung): errno is supposed to be a number / err, like in 593 Error.stackTraceLimit = tmpLimit; 594 // uvException. 595 ex.errno = code; 596 ex.code = code; 597 ex.syscall = syscall; 598 if (hostname) { 599 ex.hostname = hostname; 600 } 601 602 // eslint-disable-next-line no-restricted-syntax 603 Error.captureStackTrace(ex, excludedStackFn || dnsException); 604 return ex; 605} 606 607function connResetException(msg) { 608 // eslint-disable-next-line no-restricted-syntax 609 const ex = new Error(msg); 610 ex.code = 'ECONNRESET'; 611 return ex; 612} 613 614let maxStack_ErrorName; 615let maxStack_ErrorMessage; 616/** 617 * Returns true if `err.name` and `err.message` are equal to engine-specific 618 * values indicating max call stack size has been exceeded. 619 * "Maximum call stack size exceeded" in V8. 620 * 621 * @param {Error} err 622 * @returns {boolean} 623 */ 624function isStackOverflowError(err) { 625 if (maxStack_ErrorMessage === undefined) { 626 try { 627 function overflowStack() { overflowStack(); } 628 overflowStack(); 629 } catch (err) { 630 maxStack_ErrorMessage = err.message; 631 maxStack_ErrorName = err.name; 632 } 633 } 634 635 return err && err.name === maxStack_ErrorName && 636 err.message === maxStack_ErrorMessage; 637} 638 639// Only use this for integers! Decimal numbers do not work with this function. 640function addNumericalSeparator(val) { 641 let res = ''; 642 let i = val.length; 643 const start = val[0] === '-' ? 1 : 0; 644 for (; i >= start + 4; i -= 3) { 645 res = `_${val.slice(i - 3, i)}${res}`; 646 } 647 return `${val.slice(0, i)}${res}`; 648} 649 650// Used to enhance the stack that will be picked up by the inspector 651const kEnhanceStackBeforeInspector = Symbol('kEnhanceStackBeforeInspector'); 652 653// These are supposed to be called only on fatal exceptions before 654// the process exits. 655const fatalExceptionStackEnhancers = { 656 beforeInspector(error) { 657 if (typeof error[kEnhanceStackBeforeInspector] !== 'function') { 658 return error.stack; 659 } 660 661 try { 662 // Set the error.stack here so it gets picked up by the 663 // inspector. 664 error.stack = error[kEnhanceStackBeforeInspector](); 665 } catch { 666 // We are just enhancing the error. If it fails, ignore it. 667 } 668 return error.stack; 669 }, 670 afterInspector(error) { 671 const originalStack = error.stack; 672 let useColors = true; 673 // Some consoles do not convert ANSI escape sequences to colors, 674 // rather display them directly to the stdout. On those consoles, 675 // libuv emulates colors by intercepting stdout stream and calling 676 // corresponding Windows API functions for setting console colors. 677 // However, fatal error are handled differently and we cannot easily 678 // highlight them. On Windows, detecting whether a console supports 679 // ANSI escape sequences is not reliable. 680 if (process.platform === 'win32') { 681 const info = internalBinding('os').getOSInformation(); 682 const ver = info[2].split('.').map((a) => +a); 683 if (ver[0] !== 10 || ver[2] < 14393) { 684 useColors = false; 685 } 686 } 687 const { 688 inspect, 689 inspectDefaultOptions: { 690 colors: defaultColors 691 } 692 } = lazyInternalUtilInspect(); 693 const colors = useColors && 694 ((internalBinding('util').guessHandleType(2) === 'TTY' && 695 require('internal/tty').hasColors()) || 696 defaultColors); 697 try { 698 return inspect(error, { 699 colors, 700 customInspect: false, 701 depth: MathMax(inspect.defaultOptions.depth, 5) 702 }); 703 } catch { 704 return originalStack; 705 } 706 } 707}; 708 709module.exports = { 710 addCodeToName, // Exported for NghttpError 711 codes, 712 dnsException, 713 errnoException, 714 exceptionWithHostPort, 715 getMessage, 716 hideStackFrames, 717 isStackOverflowError, 718 connResetException, 719 uvErrmapGet, 720 uvException, 721 uvExceptionWithHostPort, 722 SystemError, 723 // This is exported only to facilitate testing. 724 E, 725 kNoOverride, 726 prepareStackTrace, 727 maybeOverridePrepareStackTrace, 728 overrideStackTrace, 729 kEnhanceStackBeforeInspector, 730 fatalExceptionStackEnhancers 731}; 732 733// To declare an error message, use the E(sym, val, def) function above. The sym 734// must be an upper case string. The val can be either a function or a string. 735// The def must be an error class. 736// The return value of the function must be a string. 737// Examples: 738// E('EXAMPLE_KEY1', 'This is the error value', Error); 739// E('EXAMPLE_KEY2', (a, b) => return `${a} ${b}`, RangeError); 740// 741// Once an error code has been assigned, the code itself MUST NOT change and 742// any given error code must never be reused to identify a different error. 743// 744// Any error code added here should also be added to the documentation 745// 746// Note: Please try to keep these in alphabetical order 747// 748// Note: Node.js specific errors must begin with the prefix ERR_ 749E('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError); 750E('ERR_ARG_NOT_ITERABLE', '%s must be iterable', TypeError); 751E('ERR_ASSERTION', '%s', Error); 752E('ERR_ASYNC_CALLBACK', '%s must be a function', TypeError); 753E('ERR_ASYNC_TYPE', 'Invalid name for async "type": %s', TypeError); 754E('ERR_BROTLI_INVALID_PARAM', '%s is not a valid Brotli parameter', RangeError); 755E('ERR_BUFFER_OUT_OF_BOUNDS', 756 // Using a default argument here is important so the argument is not counted 757 // towards `Function#length`. 758 (name = undefined) => { 759 if (name) { 760 return `"${name}" is outside of buffer bounds`; 761 } 762 return 'Attempt to access memory outside buffer bounds'; 763 }, RangeError); 764E('ERR_BUFFER_TOO_LARGE', 765 'Cannot create a Buffer larger than %s bytes', 766 RangeError); 767E('ERR_CANNOT_WATCH_SIGINT', 'Cannot watch for SIGINT signals', Error); 768E('ERR_CHILD_CLOSED_BEFORE_REPLY', 769 'Child closed before reply received', Error); 770E('ERR_CHILD_PROCESS_IPC_REQUIRED', 771 "Forked processes must have an IPC channel, missing value 'ipc' in %s", 772 Error); 773E('ERR_CHILD_PROCESS_STDIO_MAXBUFFER', '%s maxBuffer length exceeded', 774 RangeError); 775E('ERR_CONSOLE_WRITABLE_STREAM', 776 'Console expects a writable stream instance for %s', TypeError); 777E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s', Error); 778E('ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED', 779 'Custom engines not supported by this OpenSSL', Error); 780E('ERR_CRYPTO_ECDH_INVALID_FORMAT', 'Invalid ECDH format: %s', TypeError); 781E('ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY', 782 'Public key is not valid for specified curve', Error); 783E('ERR_CRYPTO_ENGINE_UNKNOWN', 'Engine "%s" was not found', Error); 784E('ERR_CRYPTO_FIPS_FORCED', 785 'Cannot set FIPS mode, it was forced with --force-fips at startup.', Error); 786E('ERR_CRYPTO_FIPS_UNAVAILABLE', 'Cannot set FIPS mode in a non-FIPS build.', 787 Error); 788E('ERR_CRYPTO_HASH_FINALIZED', 'Digest already called', Error); 789E('ERR_CRYPTO_HASH_UPDATE_FAILED', 'Hash update failed', Error); 790E('ERR_CRYPTO_INCOMPATIBLE_KEY', 'Incompatible %s: %s', Error); 791E('ERR_CRYPTO_INCOMPATIBLE_KEY_OPTIONS', 'The selected key encoding %s %s.', 792 Error); 793E('ERR_CRYPTO_INVALID_DIGEST', 'Invalid digest: %s', TypeError); 794E('ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE', 795 'Invalid key object type %s, expected %s.', TypeError); 796E('ERR_CRYPTO_INVALID_STATE', 'Invalid state for operation %s', Error); 797E('ERR_CRYPTO_PBKDF2_ERROR', 'PBKDF2 error', Error); 798E('ERR_CRYPTO_SCRYPT_INVALID_PARAMETER', 'Invalid scrypt parameter', Error); 799E('ERR_CRYPTO_SCRYPT_NOT_SUPPORTED', 'Scrypt algorithm not supported', Error); 800// Switch to TypeError. The current implementation does not seem right. 801E('ERR_CRYPTO_SIGN_KEY_REQUIRED', 'No key provided to sign', Error); 802E('ERR_DIR_CLOSED', 'Directory handle was closed', Error); 803E('ERR_DIR_CONCURRENT_OPERATION', 804 'Cannot do synchronous work on directory handle with concurrent ' + 805 'asynchronous operations', Error); 806E('ERR_DNS_SET_SERVERS_FAILED', 'c-ares failed to set servers: "%s" [%s]', 807 Error); 808E('ERR_DOMAIN_CALLBACK_NOT_AVAILABLE', 809 'A callback was registered through ' + 810 'process.setUncaughtExceptionCaptureCallback(), which is mutually ' + 811 'exclusive with using the `domain` module', 812 Error); 813E('ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE', 814 'The `domain` module is in use, which is mutually exclusive with calling ' + 815 'process.setUncaughtExceptionCaptureCallback()', 816 Error); 817E('ERR_ENCODING_INVALID_ENCODED_DATA', function(encoding, ret) { 818 this.errno = ret; 819 return `The encoded data was not valid for encoding ${encoding}`; 820}, TypeError); 821E('ERR_ENCODING_NOT_SUPPORTED', 'The "%s" encoding is not supported', 822 RangeError); 823E('ERR_FALSY_VALUE_REJECTION', function(reason) { 824 this.reason = reason; 825 return 'Promise was rejected with falsy value'; 826}, Error); 827E('ERR_FS_FILE_TOO_LARGE', 'File size (%s) is greater than possible Buffer: ' + 828 `${kMaxLength} bytes`, 829 RangeError); 830E('ERR_FS_INVALID_SYMLINK_TYPE', 831 'Symlink type must be one of "dir", "file", or "junction". Received "%s"', 832 Error); // Switch to TypeError. The current implementation does not seem right 833E('ERR_HTTP2_ALTSVC_INVALID_ORIGIN', 834 'HTTP/2 ALTSVC frames require a valid origin', TypeError); 835E('ERR_HTTP2_ALTSVC_LENGTH', 836 'HTTP/2 ALTSVC frames are limited to 16382 bytes', TypeError); 837E('ERR_HTTP2_CONNECT_AUTHORITY', 838 ':authority header is required for CONNECT requests', Error); 839E('ERR_HTTP2_CONNECT_PATH', 840 'The :path header is forbidden for CONNECT requests', Error); 841E('ERR_HTTP2_CONNECT_SCHEME', 842 'The :scheme header is forbidden for CONNECT requests', Error); 843E('ERR_HTTP2_GOAWAY_SESSION', 844 'New streams cannot be created after receiving a GOAWAY', Error); 845E('ERR_HTTP2_HEADERS_AFTER_RESPOND', 846 'Cannot specify additional headers after response initiated', Error); 847E('ERR_HTTP2_HEADERS_SENT', 'Response has already been initiated.', Error); 848E('ERR_HTTP2_HEADER_SINGLE_VALUE', 849 'Header field "%s" must only have a single value', TypeError); 850E('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED', 851 'Informational status codes cannot be used', RangeError); 852E('ERR_HTTP2_INVALID_CONNECTION_HEADERS', 853 'HTTP/1 Connection specific headers are forbidden: "%s"', TypeError); 854E('ERR_HTTP2_INVALID_HEADER_VALUE', 855 'Invalid value "%s" for header "%s"', TypeError); 856E('ERR_HTTP2_INVALID_INFO_STATUS', 857 'Invalid informational status code: %s', RangeError); 858E('ERR_HTTP2_INVALID_ORIGIN', 859 'HTTP/2 ORIGIN frames require a valid origin', TypeError); 860E('ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH', 861 'Packed settings length must be a multiple of six', RangeError); 862E('ERR_HTTP2_INVALID_PSEUDOHEADER', 863 '"%s" is an invalid pseudoheader or is used incorrectly', TypeError); 864E('ERR_HTTP2_INVALID_SESSION', 'The session has been destroyed', Error); 865E('ERR_HTTP2_INVALID_SETTING_VALUE', 866 // Using default arguments here is important so the arguments are not counted 867 // towards `Function#length`. 868 function(name, actual, min = undefined, max = undefined) { 869 this.actual = actual; 870 if (min !== undefined) { 871 this.min = min; 872 this.max = max; 873 } 874 return `Invalid value for setting "${name}": ${actual}`; 875 }, TypeError, RangeError); 876E('ERR_HTTP2_INVALID_STREAM', 'The stream has been destroyed', Error); 877E('ERR_HTTP2_MAX_PENDING_SETTINGS_ACK', 878 'Maximum number of pending settings acknowledgements', Error); 879E('ERR_HTTP2_NESTED_PUSH', 880 'A push stream cannot initiate another push stream.', Error); 881E('ERR_HTTP2_NO_SOCKET_MANIPULATION', 882 'HTTP/2 sockets should not be directly manipulated (e.g. read and written)', 883 Error); 884E('ERR_HTTP2_ORIGIN_LENGTH', 885 'HTTP/2 ORIGIN frames are limited to 16382 bytes', TypeError); 886E('ERR_HTTP2_OUT_OF_STREAMS', 887 'No stream ID is available because maximum stream ID has been reached', 888 Error); 889E('ERR_HTTP2_PAYLOAD_FORBIDDEN', 890 'Responses with %s status must not have a payload', Error); 891E('ERR_HTTP2_PING_CANCEL', 'HTTP2 ping cancelled', Error); 892E('ERR_HTTP2_PING_LENGTH', 'HTTP2 ping payload must be 8 bytes', RangeError); 893E('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED', 894 'Cannot set HTTP/2 pseudo-headers', TypeError); 895E('ERR_HTTP2_PUSH_DISABLED', 'HTTP/2 client has disabled push streams', Error); 896E('ERR_HTTP2_SEND_FILE', 'Directories cannot be sent', Error); 897E('ERR_HTTP2_SEND_FILE_NOSEEK', 898 'Offset or length can only be specified for regular files', Error); 899E('ERR_HTTP2_SESSION_ERROR', 'Session closed with error code %s', Error); 900E('ERR_HTTP2_SETTINGS_CANCEL', 'HTTP2 session settings canceled', Error); 901E('ERR_HTTP2_SOCKET_BOUND', 902 'The socket is already bound to an Http2Session', Error); 903E('ERR_HTTP2_SOCKET_UNBOUND', 904 'The socket has been disconnected from the Http2Session', Error); 905E('ERR_HTTP2_STATUS_101', 906 'HTTP status code 101 (Switching Protocols) is forbidden in HTTP/2', Error); 907E('ERR_HTTP2_STATUS_INVALID', 'Invalid status code: %s', RangeError); 908E('ERR_HTTP2_STREAM_CANCEL', function(error) { 909 let msg = 'The pending stream has been canceled'; 910 if (error) { 911 this.cause = error; 912 if (typeof error.message === 'string') 913 msg += ` (caused by: ${error.message})`; 914 } 915 return msg; 916}, Error); 917E('ERR_HTTP2_STREAM_ERROR', 'Stream closed with error code %s', Error); 918E('ERR_HTTP2_STREAM_SELF_DEPENDENCY', 919 'A stream cannot depend on itself', Error); 920E('ERR_HTTP2_TRAILERS_ALREADY_SENT', 921 'Trailing headers have already been sent', Error); 922E('ERR_HTTP2_TRAILERS_NOT_READY', 923 'Trailing headers cannot be sent until after the wantTrailers event is ' + 924 'emitted', Error); 925E('ERR_HTTP2_UNSUPPORTED_PROTOCOL', 'protocol "%s" is unsupported.', Error); 926E('ERR_HTTP_HEADERS_SENT', 927 'Cannot %s headers after they are sent to the client', Error); 928E('ERR_HTTP_INVALID_HEADER_VALUE', 929 'Invalid value "%s" for header "%s"', TypeError); 930E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s', RangeError); 931E('ERR_HTTP_TRAILER_INVALID', 932 'Trailers are invalid with this transfer encoding', Error); 933E('ERR_INCOMPATIBLE_OPTION_PAIR', 934 'Option "%s" cannot be used in combination with option "%s"', TypeError); 935E('ERR_INPUT_TYPE_NOT_ALLOWED', '--input-type can only be used with string ' + 936 'input via --eval, --print, or STDIN', Error); 937E('ERR_INSPECTOR_ALREADY_ACTIVATED', 938 'Inspector is already activated. Close it with inspector.close() ' + 939 'before activating it again.', 940 Error); 941E('ERR_INSPECTOR_ALREADY_CONNECTED', '%s is already connected', Error); 942E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error); 943E('ERR_INSPECTOR_COMMAND', 'Inspector error %d: %s', Error); 944E('ERR_INSPECTOR_NOT_ACTIVE', 'Inspector is not active', Error); 945E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available', Error); 946E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected', Error); 947E('ERR_INSPECTOR_NOT_WORKER', 'Current thread is not a worker', Error); 948E('ERR_INTERNAL_ASSERTION', (message) => { 949 const suffix = 'This is caused by either a bug in Node.js ' + 950 'or incorrect usage of Node.js internals.\n' + 951 'Please open an issue with this stack trace at ' + 952 'https://github.com/nodejs/node/issues\n'; 953 return message === undefined ? suffix : `${message}\n${suffix}`; 954}, Error); 955E('ERR_INVALID_ADDRESS_FAMILY', function(addressType, host, port) { 956 this.host = host; 957 this.port = port; 958 return `Invalid address family: ${addressType} ${host}:${port}`; 959}, RangeError); 960E('ERR_INVALID_ARG_TYPE', 961 (name, expected, actual) => { 962 assert(typeof name === 'string', "'name' must be a string"); 963 if (!ArrayIsArray(expected)) { 964 expected = [expected]; 965 } 966 967 let msg = 'The '; 968 if (name.endsWith(' argument')) { 969 // For cases like 'first argument' 970 msg += `${name} `; 971 } else { 972 const type = name.includes('.') ? 'property' : 'argument'; 973 msg += `"${name}" ${type} `; 974 } 975 msg += 'must be '; 976 977 const types = []; 978 const instances = []; 979 const other = []; 980 981 for (const value of expected) { 982 assert(typeof value === 'string', 983 'All expected entries have to be of type string'); 984 if (kTypes.includes(value)) { 985 types.push(value.toLowerCase()); 986 } else if (classRegExp.test(value)) { 987 instances.push(value); 988 } else { 989 assert(value !== 'object', 990 'The value "object" should be written as "Object"'); 991 other.push(value); 992 } 993 } 994 995 // Special handle `object` in case other instances are allowed to outline 996 // the differences between each other. 997 if (instances.length > 0) { 998 const pos = types.indexOf('object'); 999 if (pos !== -1) { 1000 types.splice(pos, 1); 1001 instances.push('Object'); 1002 } 1003 } 1004 1005 if (types.length > 0) { 1006 if (types.length > 2) { 1007 const last = types.pop(); 1008 msg += `one of type ${types.join(', ')}, or ${last}`; 1009 } else if (types.length === 2) { 1010 msg += `one of type ${types[0]} or ${types[1]}`; 1011 } else { 1012 msg += `of type ${types[0]}`; 1013 } 1014 if (instances.length > 0 || other.length > 0) 1015 msg += ' or '; 1016 } 1017 1018 if (instances.length > 0) { 1019 if (instances.length > 2) { 1020 const last = instances.pop(); 1021 msg += `an instance of ${instances.join(', ')}, or ${last}`; 1022 } else { 1023 msg += `an instance of ${instances[0]}`; 1024 if (instances.length === 2) { 1025 msg += ` or ${instances[1]}`; 1026 } 1027 } 1028 if (other.length > 0) 1029 msg += ' or '; 1030 } 1031 1032 if (other.length > 0) { 1033 if (other.length > 2) { 1034 const last = other.pop(); 1035 msg += `one of ${other.join(', ')}, or ${last}`; 1036 } else if (other.length === 2) { 1037 msg += `one of ${other[0]} or ${other[1]}`; 1038 } else { 1039 if (other[0].toLowerCase() !== other[0]) 1040 msg += 'an '; 1041 msg += `${other[0]}`; 1042 } 1043 } 1044 1045 if (actual == null) { 1046 msg += `. Received ${actual}`; 1047 } else if (typeof actual === 'function' && actual.name) { 1048 msg += `. Received function ${actual.name}`; 1049 } else if (typeof actual === 'object') { 1050 if (actual.constructor && actual.constructor.name) { 1051 msg += `. Received an instance of ${actual.constructor.name}`; 1052 } else { 1053 const inspected = lazyInternalUtilInspect() 1054 .inspect(actual, { depth: -1 }); 1055 msg += `. Received ${inspected}`; 1056 } 1057 } else { 1058 let inspected = lazyInternalUtilInspect() 1059 .inspect(actual, { colors: false }); 1060 if (inspected.length > 25) 1061 inspected = `${inspected.slice(0, 25)}...`; 1062 msg += `. Received type ${typeof actual} (${inspected})`; 1063 } 1064 return msg; 1065 }, TypeError); 1066E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => { 1067 let inspected = lazyInternalUtilInspect().inspect(value); 1068 if (inspected.length > 128) { 1069 inspected = `${inspected.slice(0, 128)}...`; 1070 } 1071 return `The argument '${name}' ${reason}. Received ${inspected}`; 1072}, TypeError, RangeError); 1073E('ERR_INVALID_ASYNC_ID', 'Invalid %s value: %s', RangeError); 1074E('ERR_INVALID_BUFFER_SIZE', 1075 'Buffer size must be a multiple of %s', RangeError); 1076E('ERR_INVALID_CALLBACK', 1077 'Callback must be a function. Received %O', TypeError); 1078E('ERR_INVALID_CHAR', 1079 // Using a default argument here is important so the argument is not counted 1080 // towards `Function#length`. 1081 (name, field = undefined) => { 1082 let msg = `Invalid character in ${name}`; 1083 if (field !== undefined) { 1084 msg += ` ["${field}"]`; 1085 } 1086 return msg; 1087 }, TypeError); 1088E('ERR_INVALID_CURSOR_POS', 1089 'Cannot set cursor row without setting its column', TypeError); 1090E('ERR_INVALID_FD', 1091 '"fd" must be a positive integer: %s', RangeError); 1092E('ERR_INVALID_FD_TYPE', 'Unsupported fd type: %s', TypeError); 1093E('ERR_INVALID_FILE_URL_HOST', 1094 'File URL host must be "localhost" or empty on %s', TypeError); 1095E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError); 1096E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError); 1097E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError); 1098E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError); 1099E('ERR_INVALID_MODULE_SPECIFIER', (request, reason, base = undefined) => { 1100 return `Invalid module "${request}" ${reason}${base ? 1101 ` imported from ${base}` : ''}`; 1102}, TypeError); 1103E('ERR_INVALID_OPT_VALUE', (name, value, reason = '') => { 1104 let inspected = typeof value === 'string' ? 1105 value : lazyInternalUtilInspect().inspect(value); 1106 if (inspected.length > 128) inspected = `${inspected.slice(0, 128)}...`; 1107 if (reason) reason = '. ' + reason; 1108 return `The value "${inspected}" is invalid for option "${name}"` + reason; 1109}, TypeError, RangeError); 1110E('ERR_INVALID_OPT_VALUE_ENCODING', 1111 'The value "%s" is invalid for option "encoding"', TypeError); 1112E('ERR_INVALID_PACKAGE_CONFIG', (path, base, message) => { 1113 return `Invalid package config ${path}${base ? ` while importing ${base}` : 1114 ''}${message ? `. ${message}` : ''}`; 1115}, Error); 1116E('ERR_INVALID_PACKAGE_TARGET', 1117 (pkgPath, key, target, isImport = false, base = undefined) => { 1118 const relError = typeof target === 'string' && !isImport && 1119 target.length && !StringPrototypeStartsWith(target, './'); 1120 if (key === '.') { 1121 assert(isImport === false); 1122 return `Invalid "exports" main target ${JSONStringify(target)} defined ` + 1123 `in the package config ${pkgPath}package.json${base ? 1124 ` imported from ${base}` : ''}${relError ? 1125 '; targets must start with "./"' : ''}`; 1126 } 1127 return `Invalid "${isImport ? 'imports' : 'exports'}" target ${ 1128 JSONStringify(target)} defined for '${key}' in the package config ${ 1129 pkgPath}package.json${base ? ` imported from ${base}` : ''}${relError ? 1130 '; targets must start with "./"' : ''}`; 1131 }, Error); 1132E('ERR_INVALID_PERFORMANCE_MARK', 1133 'The "%s" performance mark has not been set', Error); 1134E('ERR_INVALID_PROTOCOL', 1135 'Protocol "%s" not supported. Expected "%s"', 1136 TypeError); 1137E('ERR_INVALID_REPL_EVAL_CONFIG', 1138 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL', TypeError); 1139E('ERR_INVALID_REPL_INPUT', '%s', TypeError); 1140E('ERR_INVALID_RETURN_PROPERTY', (input, name, prop, value) => { 1141 return `Expected a valid ${input} to be returned for the "${prop}" from the` + 1142 ` "${name}" function but got ${value}.`; 1143}, TypeError); 1144E('ERR_INVALID_RETURN_PROPERTY_VALUE', (input, name, prop, value) => { 1145 let type; 1146 if (value && value.constructor && value.constructor.name) { 1147 type = `instance of ${value.constructor.name}`; 1148 } else { 1149 type = `type ${typeof value}`; 1150 } 1151 return `Expected ${input} to be returned for the "${prop}" from the` + 1152 ` "${name}" function but got ${type}.`; 1153}, TypeError); 1154E('ERR_INVALID_RETURN_VALUE', (input, name, value) => { 1155 let type; 1156 if (value && value.constructor && value.constructor.name) { 1157 type = `instance of ${value.constructor.name}`; 1158 } else { 1159 type = `type ${typeof value}`; 1160 } 1161 return `Expected ${input} to be returned from the "${name}"` + 1162 ` function but got ${type}.`; 1163}, TypeError); 1164E('ERR_INVALID_SYNC_FORK_INPUT', 1165 'Asynchronous forks do not support ' + 1166 'Buffer, TypedArray, DataView or string input: %s', 1167 TypeError); 1168E('ERR_INVALID_THIS', 'Value of "this" must be of type %s', TypeError); 1169E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple', TypeError); 1170E('ERR_INVALID_URI', 'URI malformed', URIError); 1171E('ERR_INVALID_URL', function(input) { 1172 this.input = input; 1173 return `Invalid URL: ${input}`; 1174}, TypeError); 1175E('ERR_INVALID_URL_SCHEME', 1176 (expected) => { 1177 if (typeof expected === 'string') 1178 expected = [expected]; 1179 assert(expected.length <= 2); 1180 const res = expected.length === 2 ? 1181 `one of scheme ${expected[0]} or ${expected[1]}` : 1182 `of scheme ${expected[0]}`; 1183 return `The URL must be ${res}`; 1184 }, TypeError); 1185E('ERR_IPC_CHANNEL_CLOSED', 'Channel closed', Error); 1186E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected', Error); 1187E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe', Error); 1188E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks', Error); 1189E('ERR_MANIFEST_ASSERT_INTEGRITY', 1190 (moduleURL, realIntegrities) => { 1191 let msg = `The content of "${ 1192 moduleURL 1193 }" does not match the expected integrity.`; 1194 if (realIntegrities.size) { 1195 const sri = [...realIntegrities.entries()].map(([alg, dgs]) => { 1196 return `${alg}-${dgs}`; 1197 }).join(' '); 1198 msg += ` Integrities found are: ${sri}`; 1199 } else { 1200 msg += ' The resource was not found in the policy.'; 1201 } 1202 return msg; 1203 }, Error); 1204E('ERR_MANIFEST_DEPENDENCY_MISSING', 1205 'Manifest resource %s does not list %s as a dependency specifier', 1206 Error); 1207E('ERR_MANIFEST_INTEGRITY_MISMATCH', 1208 'Manifest resource %s has multiple entries but integrity lists do not match', 1209 SyntaxError); 1210E('ERR_MANIFEST_INVALID_RESOURCE_FIELD', 1211 'Manifest resource %s has invalid property value for %s', 1212 TypeError); 1213E('ERR_MANIFEST_TDZ', 'Manifest initialization has not yet run', Error); 1214E('ERR_MANIFEST_UNKNOWN_ONERROR', 1215 'Manifest specified unknown error behavior "%s".', 1216 SyntaxError); 1217E('ERR_METHOD_NOT_IMPLEMENTED', 'The %s method is not implemented', Error); 1218E('ERR_MISSING_ARGS', 1219 (...args) => { 1220 assert(args.length > 0, 'At least one arg needs to be specified'); 1221 let msg = 'The '; 1222 const len = args.length; 1223 args = args.map((a) => `"${a}"`); 1224 switch (len) { 1225 case 1: 1226 msg += `${args[0]} argument`; 1227 break; 1228 case 2: 1229 msg += `${args[0]} and ${args[1]} arguments`; 1230 break; 1231 default: 1232 msg += args.slice(0, len - 1).join(', '); 1233 msg += `, and ${args[len - 1]} arguments`; 1234 break; 1235 } 1236 return `${msg} must be specified`; 1237 }, TypeError); 1238E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK', 1239 'The ES Module loader may not return a format of \'dynamic\' when no ' + 1240 'dynamicInstantiate function was provided', Error); 1241E('ERR_MISSING_OPTION', '%s is required', TypeError); 1242E('ERR_MODULE_NOT_FOUND', (path, base, type = 'package') => { 1243 return `Cannot find ${type} '${path}' imported from ${base}`; 1244}, Error); 1245E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times', Error); 1246E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function', TypeError); 1247E('ERR_NAPI_INVALID_DATAVIEW_ARGS', 1248 'byte_offset + byte_length should be less than or equal to the size in ' + 1249 'bytes of the array passed in', 1250 RangeError); 1251E('ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT', 1252 'start offset of %s should be a multiple of %s', RangeError); 1253E('ERR_NAPI_INVALID_TYPEDARRAY_LENGTH', 1254 'Invalid typed array length', RangeError); 1255E('ERR_NO_CRYPTO', 1256 'Node.js is not compiled with OpenSSL crypto support', Error); 1257E('ERR_NO_ICU', 1258 '%s is not supported on Node.js compiled without ICU', TypeError); 1259E('ERR_OUT_OF_RANGE', 1260 (str, range, input, replaceDefaultBoolean = false) => { 1261 assert(range, 'Missing "range" argument'); 1262 let msg = replaceDefaultBoolean ? str : 1263 `The value of "${str}" is out of range.`; 1264 let received; 1265 if (NumberIsInteger(input) && MathAbs(input) > 2 ** 32) { 1266 received = addNumericalSeparator(String(input)); 1267 } else if (typeof input === 'bigint') { 1268 received = String(input); 1269 if (input > 2n ** 32n || input < -(2n ** 32n)) { 1270 received = addNumericalSeparator(received); 1271 } 1272 received += 'n'; 1273 } else { 1274 received = lazyInternalUtilInspect().inspect(input); 1275 } 1276 msg += ` It must be ${range}. Received ${received}`; 1277 return msg; 1278 }, RangeError); 1279E('ERR_PACKAGE_IMPORT_NOT_DEFINED', (specifier, packagePath, base) => { 1280 return `Package import specifier "${specifier}" is not defined${packagePath ? 1281 ` in package ${packagePath}package.json` : ''} imported from ${base}`; 1282}, TypeError); 1283E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => { 1284 if (subpath === '.') 1285 return `No "exports" main defined in ${pkgPath}package.json${base ? 1286 ` imported from ${base}` : ''}`; 1287 return `Package subpath '${subpath}' is not defined by "exports" in ${ 1288 pkgPath}package.json${base ? ` imported from ${base}` : ''}`; 1289}, Error); 1290E('ERR_REQUIRE_ESM', 1291 (filename, parentPath = null, packageJsonPath = null) => { 1292 let msg = `Must use import to load ES Module: ${filename}`; 1293 if (parentPath && packageJsonPath) { 1294 const path = require('path'); 1295 const basename = path.basename(filename) === path.basename(parentPath) ? 1296 filename : path.basename(filename); 1297 msg += 1298 '\nrequire() of ES modules is not supported.\nrequire() of ' + 1299 `${filename} from ${parentPath} ` + 1300 'is an ES module file as it is a .js file whose nearest parent ' + 1301 'package.json contains "type": "module" which defines all .js ' + 1302 'files in that package scope as ES modules.\nInstead rename ' + 1303 `${basename} to end in .cjs, change the requiring code to use ` + 1304 'import(), or remove "type": "module" from ' + 1305 `${packageJsonPath}.\n`; 1306 return msg; 1307 } 1308 return msg; 1309 }, Error); 1310E('ERR_SCRIPT_EXECUTION_INTERRUPTED', 1311 'Script execution was interrupted by `SIGINT`', Error); 1312E('ERR_SERVER_ALREADY_LISTEN', 1313 'Listen method has been called more than once without closing.', Error); 1314E('ERR_SERVER_NOT_RUNNING', 'Server is not running.', Error); 1315E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound', Error); 1316E('ERR_SOCKET_BAD_BUFFER_SIZE', 1317 'Buffer size must be a positive integer', TypeError); 1318E('ERR_SOCKET_BAD_PORT', (name, port, allowZero = true) => { 1319 assert(typeof allowZero === 'boolean', 1320 "The 'allowZero' argument must be of type boolean."); 1321 const operator = allowZero ? '>=' : '>'; 1322 return `${name} should be ${operator} 0 and < 65536. Received ${port}.`; 1323}, RangeError); 1324E('ERR_SOCKET_BAD_TYPE', 1325 'Bad socket type specified. Valid types are: udp4, udp6', TypeError); 1326E('ERR_SOCKET_BUFFER_SIZE', 1327 'Could not get or set buffer size', 1328 SystemError); 1329E('ERR_SOCKET_CANNOT_SEND', 'Unable to send data', Error); 1330E('ERR_SOCKET_CLOSED', 'Socket is closed', Error); 1331E('ERR_SOCKET_DGRAM_IS_CONNECTED', 'Already connected', Error); 1332E('ERR_SOCKET_DGRAM_NOT_CONNECTED', 'Not connected', Error); 1333E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running', Error); 1334E('ERR_SRI_PARSE', 1335 'Subresource Integrity string %j had an unexpected %j at position %d', 1336 SyntaxError); 1337E('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable', Error); 1338E('ERR_STREAM_DESTROYED', 'Cannot call %s after a stream was destroyed', Error); 1339E('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); 1340E('ERR_STREAM_PREMATURE_CLOSE', 'Premature close', Error); 1341E('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF', Error); 1342E('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 1343 'stream.unshift() after end event', Error); 1344E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode', Error); 1345E('ERR_STREAM_WRITE_AFTER_END', 'write after end', Error); 1346E('ERR_SYNTHETIC', 'JavaScript Callstack', Error); 1347E('ERR_SYSTEM_ERROR', 'A system error occurred', SystemError); 1348E('ERR_TLS_CERT_ALTNAME_INVALID', function(reason, host, cert) { 1349 this.reason = reason; 1350 this.host = host; 1351 this.cert = cert; 1352 return `Hostname/IP does not match certificate's altnames: ${reason}`; 1353}, Error); 1354E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048', Error); 1355E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout', Error); 1356E('ERR_TLS_INVALID_CONTEXT', '%s must be a SecureContext', TypeError), 1357E('ERR_TLS_INVALID_STATE', 'TLS socket connection must be securely established', 1358 Error), 1359E('ERR_TLS_INVALID_PROTOCOL_VERSION', 1360 '%j is not a valid %s TLS protocol version', TypeError); 1361E('ERR_TLS_PROTOCOL_VERSION_CONFLICT', 1362 'TLS protocol version %j conflicts with secureProtocol %j', TypeError); 1363E('ERR_TLS_RENEGOTIATION_DISABLED', 1364 'TLS session renegotiation disabled for this socket', Error); 1365 1366// This should probably be a `TypeError`. 1367E('ERR_TLS_REQUIRED_SERVER_NAME', 1368 '"servername" is required parameter for Server.addContext', Error); 1369E('ERR_TLS_SESSION_ATTACK', 'TLS session renegotiation attack detected', Error); 1370E('ERR_TLS_SNI_FROM_SERVER', 1371 'Cannot issue SNI from a TLS server-side socket', Error); 1372E('ERR_TRACE_EVENTS_CATEGORY_REQUIRED', 1373 'At least one category is required', TypeError); 1374E('ERR_TRACE_EVENTS_UNAVAILABLE', 'Trace events are unavailable', Error); 1375E('ERR_TRANSFORM_ALREADY_TRANSFORMING', 1376 'Calling transform done when still transforming', Error); 1377 1378// This should probably be a `RangeError`. 1379E('ERR_TRANSFORM_WITH_LENGTH_0', 1380 'Calling transform done when writableState.length != 0', Error); 1381E('ERR_TTY_INIT_FAILED', 'TTY initialization failed', SystemError); 1382E('ERR_UNAVAILABLE_DURING_EXIT', 'Cannot call function in process exit ' + 1383 'handler', Error); 1384E('ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET', 1385 '`process.setupUncaughtExceptionCapture()` was called while a capture ' + 1386 'callback was already active', 1387 Error); 1388E('ERR_UNESCAPED_CHARACTERS', '%s contains unescaped characters', TypeError); 1389E('ERR_UNHANDLED_ERROR', 1390 // Using a default argument here is important so the argument is not counted 1391 // towards `Function#length`. 1392 (err = undefined) => { 1393 const msg = 'Unhandled error.'; 1394 if (err === undefined) return msg; 1395 return `${msg} (${err})`; 1396 }, Error); 1397E('ERR_UNKNOWN_BUILTIN_MODULE', 'No such built-in module: %s', Error); 1398E('ERR_UNKNOWN_CREDENTIAL', '%s identifier does not exist: %s', Error); 1399E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s', TypeError); 1400E('ERR_UNKNOWN_FILE_EXTENSION', 1401 'Unknown file extension "%s" for %s', 1402 TypeError); 1403E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError); 1404E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError); 1405E('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " + 1406'resolving ES modules imported from %s', Error); 1407E('ERR_UNSUPPORTED_ESM_URL_SCHEME', (url) => { 1408 let msg = 'Only file and data URLs are supported by the default ESM loader'; 1409 if (isWindows && url.protocol.length === 2) { 1410 msg += 1411 '. On Windows, absolute paths must be valid file:// URLs'; 1412 } 1413 msg += `. Received protocol '${url.protocol}'`; 1414 return msg; 1415}, Error); 1416 1417// This should probably be a `TypeError`. 1418E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', 1419 'At least one valid performance entry type is required', Error); 1420E('ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING', 1421 'A dynamic import callback was not specified.', TypeError); 1422E('ERR_VM_MODULE_ALREADY_LINKED', 'Module has already been linked', Error); 1423E('ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA', 1424 'Cached data cannot be created for a module which has been evaluated', Error); 1425E('ERR_VM_MODULE_DIFFERENT_CONTEXT', 1426 'Linked modules must use the same context', Error); 1427E('ERR_VM_MODULE_LINKING_ERRORED', 1428 'Linking has already failed for the provided module', Error); 1429E('ERR_VM_MODULE_NOT_MODULE', 1430 'Provided module is not an instance of Module', Error); 1431E('ERR_VM_MODULE_STATUS', 'Module status %s', Error); 1432E('ERR_WASI_ALREADY_STARTED', 'WASI instance has already started', Error); 1433E('ERR_WORKER_INIT_FAILED', 'Worker initialization failure: %s', Error); 1434E('ERR_WORKER_INVALID_EXEC_ARGV', (errors, msg = 'invalid execArgv flags') => 1435 `Initiated Worker with ${msg}: ${errors.join(', ')}`, 1436 Error); 1437E('ERR_WORKER_NOT_RUNNING', 'Worker instance not running', Error); 1438E('ERR_WORKER_OUT_OF_MEMORY', 1439 'Worker terminated due to reaching memory limit: %s', Error); 1440E('ERR_WORKER_PATH', (filename) => 1441 'The worker script or module filename must be an absolute path or a ' + 1442 'relative path starting with \'./\' or \'../\'.' + 1443 (filename.startsWith('file://') ? 1444 ' Wrap file:// URLs with `new URL`.' : '' 1445 ) + 1446 ` Received "${filename}"`, 1447 TypeError); 1448E('ERR_WORKER_UNSERIALIZABLE_ERROR', 1449 'Serializing an uncaught exception failed', Error); 1450E('ERR_WORKER_UNSUPPORTED_EXTENSION', 1451 'The worker script extension must be ".js", ".mjs", or ".cjs". Received "%s"', 1452 TypeError); 1453E('ERR_WORKER_UNSUPPORTED_OPERATION', 1454 '%s is not supported in workers', TypeError); 1455E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed', Error); 1456