diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-01-19 10:35:39 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-01-24 13:16:07 +0100 |
commit | 72bb4445c64af98f3e481c11320afbfb995f010c (patch) | |
tree | 282d7240fb99f92a2332a74b6044f04317b5b78a /test/message | |
parent | 7a23fc076045e767b922343c226d8492cc98cb93 (diff) | |
download | android-node-v8-72bb4445c64af98f3e481c11320afbfb995f010c.tar.gz android-node-v8-72bb4445c64af98f3e481c11320afbfb995f010c.tar.bz2 android-node-v8-72bb4445c64af98f3e481c11320afbfb995f010c.zip |
assert: wrap original error in ifError
It is hard to know where ifError is actually triggered due to the
original error being thrown.
This changes it by wrapping the original error in a AssertionError.
This has the positive effect of also making clear that it is indeed
a assertion function that triggered that error.
The original stack can still be accessed by checking the `actual`
property.
PR-URL: https://github.com/nodejs/node/pull/18247
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/message')
-rw-r--r-- | test/message/if-error-has-good-stack.js | 22 | ||||
-rw-r--r-- | test/message/if-error-has-good-stack.out | 19 |
2 files changed, 41 insertions, 0 deletions
diff --git a/test/message/if-error-has-good-stack.js b/test/message/if-error-has-good-stack.js new file mode 100644 index 0000000000..1db25d2fa5 --- /dev/null +++ b/test/message/if-error-has-good-stack.js @@ -0,0 +1,22 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); + +let err; +// Create some random error frames. +(function a() { + (function b() { + (function c() { + err = new Error('test error'); + })(); + })(); +})(); + +(function x() { + (function y() { + (function z() { + assert.ifError(err); + })(); + })(); +})(); diff --git a/test/message/if-error-has-good-stack.out b/test/message/if-error-has-good-stack.out new file mode 100644 index 0000000000..fa72322b44 --- /dev/null +++ b/test/message/if-error-has-good-stack.out @@ -0,0 +1,19 @@ +assert.js:* + throw newErr; + ^ + +AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error + at z (*/if-error-has-good-stack.js:*:* + at y (*/if-error-has-good-stack.js:*:*) + at x (*/if-error-has-good-stack.js:*:*) + at Object.<anonymous> (*/if-error-has-good-stack.js:*:*) + at c (*/if-error-has-good-stack.js:*:*) + at b (*/if-error-has-good-stack.js:*:*) + at a (*/if-error-has-good-stack.js:*:*) + at Object.<anonymous> (*/if-error-has-good-stack.js:*:*) + at Module._compile (module.js:*:*) + at Object.Module._extensions..js (module.js:*:*) + at Module.load (module.js:*:*) + at tryModuleLoad (module.js:*:*) + at Function.Module._load (module.js:*:*) + at Function.Module.runMain (module.js:*:*) |