0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/message/if-error-has-good-stack.js
Ruben Bridgewater 72bb4445c6
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>
2018-01-24 13:16:07 +01:00

23 lines
338 B
JavaScript

'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);
})();
})();
})();