From e97e32a7ef35c8ab03befb937b022324b60398a7 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Wed, 17 Apr 2024 22:30:47 +0530 Subject: [PATCH 1/2] Keep error's original messages for NoSuchElementError. --- lib/transport/errors/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/transport/errors/index.js b/lib/transport/errors/index.js index 903084358d..5f5e2ccd80 100644 --- a/lib/transport/errors/index.js +++ b/lib/transport/errors/index.js @@ -155,11 +155,13 @@ module.exports = { if (err && (err.name in SeleniumNightwatchErrorCodeMap)) { const statusCode = SeleniumNightwatchErrorCodeMap[err.name]; - return { - ...err, - ...Errors[statusCode], - id: statusCode - }; + for (const [key, value] of Object.entries(Errors[statusCode])) { + err[key] ||= value; + } + + err.id = statusCode; + + return err; } else if (err && err.name && (err.stack || err.stackTrace)){ return err; } From 6b246914eb1fb2d72e7c336670d8c519f6907919 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Wed, 17 Apr 2024 23:27:17 +0530 Subject: [PATCH 2/2] Don't mutate original error object. --- lib/transport/errors/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/transport/errors/index.js b/lib/transport/errors/index.js index 5f5e2ccd80..4e1fc506ee 100644 --- a/lib/transport/errors/index.js +++ b/lib/transport/errors/index.js @@ -155,13 +155,16 @@ module.exports = { if (err && (err.name in SeleniumNightwatchErrorCodeMap)) { const statusCode = SeleniumNightwatchErrorCodeMap[err.name]; + const error = { + ...err, + id: statusCode + }; + for (const [key, value] of Object.entries(Errors[statusCode])) { - err[key] ||= value; + error[key] ||= value; } - err.id = statusCode; - - return err; + return error; } else if (err && err.name && (err.stack || err.stackTrace)){ return err; }