diff --git a/x-pack/plugins/canvas/public/components/arg_form/arg_form.js b/x-pack/plugins/canvas/public/components/arg_form/arg_form.js index 0f22307c9cd1..1e79b8152c9d 100644 --- a/x-pack/plugins/canvas/public/components/arg_form/arg_form.js +++ b/x-pack/plugins/canvas/public/components/arg_form/arg_form.js @@ -75,7 +75,6 @@ export const ArgForm = (props) => { Promise.resolve().then(() => { // Provide templates with a renderError method, and wrap the error in a known error type // to stop Kibana's window.error from being called - // see window_error_handler.js for details, isMounted.current && setRenderError(true); }); }, diff --git a/x-pack/plugins/canvas/public/lib/window_error_handler.js b/x-pack/plugins/canvas/public/lib/window_error_handler.js deleted file mode 100644 index 0d24a9898612..000000000000 --- a/x-pack/plugins/canvas/public/lib/window_error_handler.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as knownErrors from '../../common/lib/errors'; - -const oldHandler = window.onerror; - -function showError(err) { - const body = document.querySelector('body'); - const notice = document.createElement('div'); - notice.classList.add('window-error'); - - const close = document.createElement('a'); - close.textContent = 'close'; - close.onclick = (ev) => { - ev.preventDefault(); - body.removeChild(notice); - }; - notice.appendChild(close); - - notice.insertAdjacentHTML('beforeend', '
Check console for more information
`); - body.appendChild(notice); -} - -window.canvasInitErrorHandler = () => { - // React will delegate to window.onerror, even when errors are caught with componentWillCatch, - // so check for a known custom error type and skip the default error handling when we find one - window.onerror = (...args) => { - const [message, , , , err] = args; - - // ResizeObserver error does not have an `err` object - // It is thrown during workpad loading due to layout thrashing - // https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded - // https://github.com/elastic/eui/issues/3346 - console.log(message); - const isKnownError = - message.includes('ResizeObserver loop') || - Object.keys(knownErrors).find((errorName) => { - return err.constructor.name === errorName || message.indexOf(errorName) >= 0; - }); - if (isKnownError) { - return; - } - - // uncaught errors are silenced in dev mode - // NOTE: react provides no way I can tell to distingish that an error came from react, it just - // throws generic Errors. In development mode, it throws those errors even if you catch them in - // an error boundary. This uses in the stack trace to try to detect it, but that stack changes - // between development and production modes. Fortunately, beginWork exists in both, so it uses - // a mix of the runtime mode and checking for another react method (renderRoot) for development - // TODO: this is *super* fragile. If the React method names ever change, which seems kind of likely, - // this check will break. - const isProduction = process.env.NODE_ENV === 'production'; - if (!isProduction) { - // TODO: we should do something here to let the user know something failed, - // but we don't currently have an error logging service - console.error(err); - console.warn(`*** Uncaught error swallowed in dev mode *** - - Check and fix the above error. This will blow up Kibana when run in production mode!`); - showError(err); - return; - } - - // fall back to the default kibana uncaught error handler - oldHandler(...args); - }; -}; - -window.canvasRestoreErrorHandler = () => { - window.onerror = oldHandler; -};