diff --git a/src/errors.js b/src/errors.js index 84dc5c2c9..030467266 100644 --- a/src/errors.js +++ b/src/errors.js @@ -86,12 +86,22 @@ function E(code, message, Base) { } } - NodeError.prototype.name = Base.name + Object.defineProperties(NodeError.prototype, { + name: { + value: Base.name, + writable: true, + enumerable: false, + configurable: true, + }, + toString: { + value() { return `${this.name} [${code}]: ${this.message}`; }, + writable: true, + enumerable: false, + configurable: true, + } + }); NodeError.prototype.code = code NodeError.prototype[kIsNodeError] = true - NodeError.prototype.toString = function () { - return `${this.name} [${code}]: ${this.message}` - } codes[code] = NodeError }