Skip to content

Commit

Permalink
Merge pull request #14547 from logonoff/namesp
Browse files Browse the repository at this point in the history
OCPBUGS-44920: save all `window.windowError`s for easier debugging
  • Loading branch information
openshift-merge-bot[bot] authored Dec 5, 2024
2 parents 859242b + 4325269 commit 74d43c1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/@types/console/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declare interface Window {
k8sMode: string;
capabilities: Record<string, string>[];
};
windowError?: string;
windowError?: string[];
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: Function;
i18n?: {}; // i18next instance, only available in development builds for debugging
store?: {}; // Redux store, only available in development builds for debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ declare interface Window {
SERVER_FLAGS: {
basePath: string;
};
windowError?: string;
windowError?: string[];
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: Function;
}
8 changes: 6 additions & 2 deletions frontend/packages/integration-tests-cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { a11yTestResults } from './a11y';
import './admin';

declare global {
interface Window {
windowError?: string[];
}

namespace Cypress {
interface Chainable {
visitAndWait(
Expand Down Expand Up @@ -82,8 +86,8 @@ after(() => {
});

export const checkErrors = () =>
cy.window().then((win) => {
assert.isTrue(!win.windowError, win.windowError);
cy.window().then(({ windowError }) => {
assert.isTrue(!windowError || windowError.length === 0, String(windowError));
});

export const testName = `test-${Math.random()
Expand Down
6 changes: 3 additions & 3 deletions frontend/public/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,18 @@ graphQLReady.onReady(() => {
setInterval(() => store.dispatch(UIActions.updateTimestamps(Date.now())), 10000);

// Used by GUI tests to check for unhandled exceptions
window.windowError = null;
window.windowError = [];
window.onerror = (message, source, lineno, colno, error) => {
const formattedStack = error?.stack?.replace(/\\n/g, '\n');
const formattedMessage = `unhandled error: ${message} ${formattedStack || ''}`;
window.windowError = formattedMessage;
window.windowError.push(formattedMessage);
// eslint-disable-next-line no-console
console.error(formattedMessage, error || message);
};
window.onunhandledrejection = (promiseRejectionEvent) => {
const { reason } = promiseRejectionEvent;
const formattedMessage = `unhandled promise rejection: ${reason}`;
window.windowError = formattedMessage;
window.windowError.push(formattedMessage);
// eslint-disable-next-line no-console
console.error(formattedMessage, reason);
};
Expand Down
5 changes: 3 additions & 2 deletions frontend/public/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ export const init = () => {
},
saveMissing: true,
missingKeyHandler: function (lng, ns, key) {
window.windowError = `Missing i18n key "${key}" in namespace "${ns}" and language "${lng}".`;
const error = `Missing i18n key "${key}" in namespace "${ns}" and language "${lng}".`;
window.windowError = [...(window.windowError || []), error]; // OCPBUGS-45139: store all i18n errors for easy debugging
// eslint-disable-next-line no-console
console.error(window.windowError);
console.error(error);
},
})
// Update loading promise and pass values and errors to the caller
Expand Down

0 comments on commit 74d43c1

Please sign in to comment.