From b83274756e7753aa8194abcc391765fb70986f5f Mon Sep 17 00:00:00 2001 From: Katerina Koukiou Date: Fri, 15 Sep 2023 16:39:55 +0200 Subject: [PATCH] webui: add report for JS bugs + test --- ui/webui/src/components/Error.jsx | 9 +++++++-- ui/webui/src/components/app.jsx | 15 +++++++++++++-- ui/webui/test/check-basic | 25 ++++++++++++++++++++++++- ui/webui/test/reference | 2 +- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/ui/webui/src/components/Error.jsx b/ui/webui/src/components/Error.jsx index 8c37434c797..0ffbea9c350 100644 --- a/ui/webui/src/components/Error.jsx +++ b/ui/webui/src/components/Error.jsx @@ -178,14 +178,19 @@ export const BZReportModal = ({ const addExceptionDataToReportURL = (url, exception) => { const newUrl = new URL(url); + const backendMessage = exception.backendMessage ? exception.backendMessage + (exception.jsMessage ? " " : "") : ""; + const bothSeparator = exception.backendMessage && exception.jsMessage ? "\n" : ""; const context = exception.contextData?.context ? exception.contextData?.context + " " : ""; + const jsMessage = exception.jsMessage ? exception.jsMessage : ""; + const name = exception.name ? exception.name + ": " : ""; + const stackTrace = exception.stack ? "\n\nStackTrace: " + exception.stack : ""; newUrl.searchParams.append( "short_desc", - "WebUI: " + context + exception.name + ": " + exception.message + "WebUI: " + context + name + backendMessage + jsMessage ); newUrl.searchParams.append( "comment", - "Installer WebUI Critical Error:\n" + context + exception.name + ": " + exception.message + "Installer WebUI Critical Error:\n" + context + name + backendMessage + bothSeparator + jsMessage + stackTrace ); return newUrl.href; }; diff --git a/ui/webui/src/components/app.jsx b/ui/webui/src/components/app.jsx index e952d4e85c0..0dd93758894 100644 --- a/ui/webui/src/components/app.jsx +++ b/ui/webui/src/components/app.jsx @@ -54,6 +54,7 @@ export const Application = () => { const [state, dispatch] = useReducerWithThunk(reducer, initialState); const [storeInitilized, setStoreInitialized] = useState(false); const criticalError = state?.error?.criticalError; + const [jsError, setJsEroor] = useState(); const onCritFail = useCallback((contextData) => { return errorHandlerWithContext(contextData, exc => dispatch(setCriticalErrorAction(exc))); @@ -62,6 +63,12 @@ export const Application = () => { useEffect(() => { // Before unload ask the user for verification window.onbeforeunload = e => ""; + + // Listen on JS errors + window.onerror = (message, url, line, col, errObj) => { + setJsEroor(errObj); + }; + cockpit.file("/run/anaconda/bus.address").watch(address => { setCriticalErrorAction(); const clients = [ @@ -115,8 +122,11 @@ export const Application = () => { const page = ( - {criticalError && - } + {(criticalError || jsError) && + } @@ -137,6 +147,7 @@ export const Application = () => { localizationData={state.localization} dispatch={dispatch} conf={conf} + osRelease={osRelease} /> diff --git a/ui/webui/test/check-basic b/ui/webui/test/check-basic index 09d8fbc8c08..07885c76aed 100755 --- a/ui/webui/test/check-basic +++ b/ui/webui/test/check-basic @@ -21,7 +21,7 @@ from installer import Installer from language import Language from review import Review from storage import Storage -from testlib import nondestructive, test_main, wait # pylint: disable=import-error +from testlib import nondestructive, test_main, wait, Error # pylint: disable=import-error from utils import pretend_live_iso, get_pretty_name @@ -213,6 +213,29 @@ class TestBasic(anacondalib.VirtInstallMachineCase): self._testLogReview(b, m, "critical-error") + def testJsErrorHandling(self): + b = self.browser + m = self.machine + i = Installer(b, m) + + i.open() + + b.wait_not_present("#critical-error-bz-report-modal.pf-v5-c-modal-box") + + with self.assertRaises(RuntimeError): + b.eval_js("window.setTimeout(function() {throw new Error('Unexpected JS error')}, 0);") + # Some round trips, one of which should update the deferred exception + for _ in range(0, 5): + b.wait_in_text("#critical-error-bz-report-modal-details", "Error: Unexpected JS error") + time.sleep(2) + + b.assert_pixels( + "#critical-error-bz-report-modal.pf-v5-c-modal-box", + "js-error-modal", + wait_animations=False, + ignore=["#critical-error-bz-report-modal-review-log"] + ) + if __name__ == '__main__': test_main() diff --git a/ui/webui/test/reference b/ui/webui/test/reference index 094d2484571..0d3835a5522 160000 --- a/ui/webui/test/reference +++ b/ui/webui/test/reference @@ -1 +1 @@ -Subproject commit 094d248457119ead6c5c07f833e7b985789b27df +Subproject commit 0d3835a5522c4508a3da82272ecad7d28707510f