MCPcopy Index your code
hub / github.com/nodejs/node / makeNodeErrorWithCode

Function makeNodeErrorWithCode

lib/internal/errors.js:434–532  ·  view source on GitHub ↗
(Base, key)

Source from the content-addressed store, hash-verified

432}
433
434function makeNodeErrorWithCode(Base, key) {
435 const msg = messages.get(key);
436 const expectedLength = typeof msg !== 'string' ? -1 : getExpectedArgumentLength(msg);
437
438 switch (expectedLength) {
439 case 0: {
440 class NodeError extends Base {
441 code = key;
442
443 constructor(...args) {
444 assert(
445 args.length === 0,
446 `Code: ${key}; The provided arguments length (${args.length}) does not ` +
447 `match the required ones (${expectedLength}).`,
448 );
449 super(msg);
450 }
451
452 // This is a workaround for wpt tests that expect that the error
453 // constructor has a `name` property of the base class.
454 get ['constructor']() {
455 return Base;
456 }
457
458 get [kIsNodeError]() {
459 return true;
460 }
461
462 toString() {
463 return `${this.name} [${key}]: ${this.message}`;
464 }
465 }
466 return NodeError;
467 }
468 case -1: {
469 class NodeError extends Base {
470 code = key;
471
472 constructor(...args) {
473 super();
474 ObjectDefineProperty(this, 'message', {
475 __proto__: null,
476 value: getMessage(key, args, this),
477 enumerable: false,
478 writable: true,
479 configurable: true,
480 });
481 }
482
483 // This is a workaround for wpt tests that expect that the error
484 // constructor has a `name` property of the base class.
485 get ['constructor']() {
486 return Base;
487 }
488
489 get [kIsNodeError]() {
490 return true;
491 }

Callers 1

EFunction · 0.85

Calls 2

getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…