Skip to content

Commit 431a9af

Browse files
authored
Evade override mistake (#474)
1 parent 81c5264 commit 431a9af

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/errors.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,22 @@ function E(code, message, Base) {
8686
}
8787
}
8888

89-
NodeError.prototype.name = Base.name
89+
Object.defineProperties(NodeError.prototype, {
90+
name: {
91+
value: Base.name,
92+
writable: true,
93+
enumerable: false,
94+
configurable: true,
95+
},
96+
toString: {
97+
value() { return `${this.name} [${code}]: ${this.message}`; },
98+
writable: true,
99+
enumerable: false,
100+
configurable: true,
101+
}
102+
});
90103
NodeError.prototype.code = code
91104
NodeError.prototype[kIsNodeError] = true
92-
NodeError.prototype.toString = function () {
93-
return `${this.name} [${code}]: ${this.message}`
94-
}
95105

96106
codes[code] = NodeError
97107
}

0 commit comments

Comments
 (0)