From 4f75e07fb3f80a01856be7ef30bc1b5d5f86d827 Mon Sep 17 00:00:00 2001 From: Nihar Phansalkar Date: Thu, 21 Dec 2023 15:40:22 +0000 Subject: [PATCH] lib: added isNativeError check to assert.js Added the function for compliance with frameworks such as Jest Fixes: #50780 --- lib/assert.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/assert.js b/lib/assert.js index 9dfcf80a913942c..1078255cea5ba25 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -74,6 +74,7 @@ const { validateFunction, } = require('internal/validators'); const { fileURLToPath } = require('internal/url'); +const { isNativeError } = internalBinding('types'); let isDeepEqual; let isDeepStrictEqual; @@ -393,6 +394,8 @@ function innerOk(fn, argLen, value, message) { } else if (message == null) { generatedMessage = true; message = getErrMessage(message, fn); + } else if (isNativeError(message)) { + throw message; } else if (message instanceof Error) { throw message; }