Ensure all Error objects contain a stack prop #3653

This commit is contained in:
Lovell Fuller
2023-10-11 14:59:21 +01:00
parent 68fa84ef6f
commit 47e76c9981
7 changed files with 135 additions and 47 deletions

View File

@@ -137,6 +137,19 @@ const invalidParameterError = function (name, expected, actual) {
);
};
/**
* Ensures an Error from C++ contains a JS stack.
*
* @param {Error} native - Error with message from C++.
* @param {Error} context - Error with stack from JS.
* @returns {Error} Error with message and stack.
* @private
*/
const nativeError = function (native, context) {
context.message = native.message;
return context;
};
module.exports = {
defined,
object,
@@ -151,5 +164,6 @@ module.exports = {
integer,
inRange,
inArray,
invalidParameterError
invalidParameterError,
nativeError
};