diff options
Diffstat (limited to 'lib/internal/assert/assertion_error.js')
-rw-r--r-- | lib/internal/assert/assertion_error.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index a13a610da1..ded5ef00c9 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -388,12 +388,25 @@ class AssertionError extends Error { } this.generatedMessage = !message; - this.name = 'AssertionError [ERR_ASSERTION]'; + Object.defineProperty(this, 'name', { + value: 'AssertionError [ERR_ASSERTION]', + enumerable: false, + writable: true, + configurable: true + }); this.code = 'ERR_ASSERTION'; this.actual = actual; this.expected = expected; this.operator = operator; Error.captureStackTrace(this, stackStartFn); + // Create error message including the error code in the name. + this.stack; + // Reset the name. + this.name = 'AssertionError'; + } + + toString() { + return `${this.name} [${this.code}]: ${this.message}`; } [inspect.custom](recurseTimes, ctx) { |