diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-03-13 17:43:00 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-25 02:29:48 +0300 |
commit | b9f1e572017c146da66077331260bac0e60c0928 (patch) | |
tree | 94813ea917a49cb573d141f225922534770e6eed /lib/internal/assert.js | |
parent | 237d9f97165da39d1e540699294cf2dc83bbc2d3 (diff) |
lib: throw a special error in internal/assert
Instead of using the public AssertionError, use a simplified
error that describes potential causes of these assertions
and suggests the user to open an issue.
PR-URL: https://github.com/nodejs/node/pull/26635
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/assert.js')
-rw-r--r-- | lib/internal/assert.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/internal/assert.js b/lib/internal/assert.js index e403fd4b60e..b62b2753c0b 100644 --- a/lib/internal/assert.js +++ b/lib/internal/assert.js @@ -1,13 +1,22 @@ 'use strict'; +let error; +function lazyError() { + if (!error) { + error = require('internal/errors').codes.ERR_INTERNAL_ASSERTION; + } + return error; +} function assert(value, message) { if (!value) { - require('assert')(value, message); + const ERR_INTERNAL_ASSERTION = lazyError(); + throw new ERR_INTERNAL_ASSERTION(message); } } function fail(message) { - require('assert').fail(message); + const ERR_INTERNAL_ASSERTION = lazyError(); + throw new ERR_INTERNAL_ASSERTION(message); } assert.fail = fail; |