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>
22 lines
521 B
JavaScript
22 lines
521 B
JavaScript
'use strict';
|
|
|
|
// Used to test the `uncaughtException` err object
|
|
|
|
const assert = require('assert');
|
|
const { callbackify } = require('util');
|
|
|
|
{
|
|
const sentinel = new Error(__filename);
|
|
process.once('uncaughtException', (err) => {
|
|
assert.notStrictEqual(err, sentinel);
|
|
// Calling test will use `stdout` to assert value of `err.message`
|
|
console.log(err.message);
|
|
});
|
|
|
|
function fn() {
|
|
return Promise.reject(sentinel);
|
|
}
|
|
|
|
const cbFn = callbackify(fn);
|
|
cbFn((err, ret) => assert.ifError(err));
|
|
}
|