Skip to content

Commit

Permalink
webui: add report for JS bugs + test
Browse files Browse the repository at this point in the history
  • Loading branch information
KKoukiou committed Oct 18, 2023
1 parent 98f01f4 commit b832747
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
9 changes: 7 additions & 2 deletions ui/webui/src/components/Error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
15 changes: 13 additions & 2 deletions ui/webui/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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 = [
Expand Down Expand Up @@ -115,8 +122,11 @@ export const Application = () => {
const page = (
<OsReleaseContext.Provider value={osRelease}>
<SystemTypeContext.Provider value={systemType}>
{criticalError &&
<CriticalError exception={criticalError} isConnected={state.network.connected} reportLinkURL={bzReportURL} />}
{(criticalError || jsError) &&
<CriticalError
exception={{ ...criticalError, jsMessage: jsError?.message, backendMessage: criticalError?.message, stack: jsError?.stack }}
isConnected={state.network.connected}
reportLinkURL={bzReportURL} />}
<Page
data-debug={conf.Anaconda.debug}
>
Expand All @@ -137,6 +147,7 @@ export const Application = () => {
localizationData={state.localization}
dispatch={dispatch}
conf={conf}
osRelease={osRelease}
/>
</WithDialogs>
</AddressContext.Provider>
Expand Down
25 changes: 24 additions & 1 deletion ui/webui/test/check-basic
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion ui/webui/test/reference

0 comments on commit b832747

Please sign in to comment.