summaryrefslogtreecommitdiff
path: root/lib/assert.js
diff options
context:
space:
mode:
authorgeek <wpreul@gmail.com>2017-09-09 20:36:47 -0500
committercjihrig <cjihrig@gmail.com>2017-09-12 15:02:00 -0400
commite13d1df89bbaf26601b6c1c8406113b80bb6a95c (patch)
tree4e08967cedcf34eba8285bc5c6bd98cd8e83115f /lib/assert.js
parenta10856a7d31f9b641bf330fe9edfa9728f4b1c78 (diff)
downloadandroid-node-v8-e13d1df89bbaf26601b6c1c8406113b80bb6a95c.tar.gz
android-node-v8-e13d1df89bbaf26601b6c1c8406113b80bb6a95c.tar.bz2
android-node-v8-e13d1df89bbaf26601b6c1c8406113b80bb6a95c.zip
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>
Diffstat (limited to 'lib/assert.js')
-rw-r--r--lib/assert.js2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/assert.js b/lib/assert.js
index 2c52fcc199..6cbebcc4d8 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -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,