From 111dd3a19899e4fc37bf7e2f7557ab66fe2a1dbe Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 27 Apr 2023 16:53:29 +0000 Subject: [PATCH] Bug 1829630 - [bidi] Throw explicit error for missing stacks in script module r=webdriver-reviewers,Sasha Depends on D176353 Differential Revision: https://phabricator.services.mozilla.com/D176354 --- .../modules/windowglobal/script.sys.mjs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs index e0b3ce84047c..fd2321de4c00 100644 --- a/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs +++ b/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs @@ -66,8 +66,18 @@ class ScriptModule extends WindowGlobalBiDiModule { #buildExceptionDetails(exception, stack, realm, resultOwnership, options) { exception = this.#toRawObject(exception); - const frames = lazy.getFramesFromStack(stack) || []; + // A stacktrace is mandatory to build exception details and a missing stack + // means we encountered an unexpected issue. Throw with an explicit error. + if (!stack) { + throw new Error( + `Missing stack, unable to build exceptionDetails for exception: ${lazy.stringify( + exception + )}` + ); + } + + const frames = lazy.getFramesFromStack(stack) || []; const callFrames = frames // Remove chrome/internal frames .filter(frame => !lazy.isChromeFrame(frame))