mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
assert: support custom errors
This commit adds special handling of Error instances when passed as the message argument to assert functions. With this commit, if an Error is passed as the message, then that Error is thrown instead of an AssertionError. PR-URL: https://github.com/nodejs/node/pull/15304 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
a10856a7d3
commit
e13d1df89b
4 changed files with 93 additions and 18 deletions
|
@ -38,6 +38,8 @@ const assert = module.exports = ok;
|
|||
// display purposes.
|
||||
|
||||
function innerFail(actual, expected, message, operator, stackStartFunction) {
|
||||
if (message instanceof Error) throw message;
|
||||
|
||||
throw new errors.AssertionError({
|
||||
message,
|
||||
actual,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue