errors: AssertionError moved to internal/error

AssertionError class is moved to interna/error
in reference to the TODO in assert.js. This was
suggested to get rid of the cyclic dependency
between assert.js and internal/error.js

PR-URL: https://github.com/nodejs/node/pull/12906
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Faiz Halde authored and James M Snell committed 2017-05-23 07:43:53 -07:00
1 parent 9836cf5717
commit 425aba4f36
3 files changed
+35 -35

No files matched your search

+25
View File
@@ -41,6 +41,30 @@ function makeNodeError(Base) {
};
}
class AssertionError extends Error {
constructor(options) {
if (typeof options !== 'object' || options === null) {
throw new exports.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'object');
}
const util = lazyUtil();
const assert = lazyAssert();
const message = options.message ||
`${util.inspect(options.actual).slice(0, 128)} ` +
`${options.operator} ` +
util.inspect(options.expected).slice(0, 128);
super(message);
this.generatedMessage = !options.message;
this.name = 'AssertionError [ERR_ASSERTION]';
this.code = 'ERR_ASSERTION';
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
const stackStartFunction = options.stackStartFunction || assert.fail;
Error.captureStackTrace(this, stackStartFunction);
}
}
function message(key, args) {
const assert = lazyAssert();
assert.strictEqual(typeof key, 'string');
@@ -69,6 +93,7 @@ module.exports = exports = {
Error: makeNodeError(Error),
TypeError: makeNodeError(TypeError),
RangeError: makeNodeError(RangeError),
AssertionError,
E // This is exported only to facilitate testing.
};