diff --git a/packages/desktop-client/src/browser-server.js b/packages/desktop-client/src/browser-server.js index 6efb691f2db35de0a616cd248cf4bd6ae6cc02d8..3052ea8f451187c477d5a4e83346bfc4acc89724 100644 --- a/packages/desktop-client/src/browser-server.js +++ b/packages/desktop-client/src/browser-server.js @@ -12,15 +12,15 @@ let hasInitialized = false; const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => { try { importScripts(script); - } catch (e) { + } catch (error) { // Break if maxRetries has exceeded if (maxRetries <= 0) { - throw e; + throw error; } else { console.groupCollapsed( `Failed to load backend, will retry ${maxRetries} more time(s)`, ); - console.log(e); + console.log(error); console.groupEnd(); } @@ -36,39 +36,50 @@ const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => { } }; -self.addEventListener('message', async e => { - if (!hasInitialized) { - const msg = e.data; +self.addEventListener('message', async event => { + try { + if (!hasInitialized) { + const msg = event.data; - if (msg.type === 'init') { - hasInitialized = true; - const isDev = !!msg.isDev; - // let version = msg.version; - const hash = msg.hash; + if (msg.type === 'init') { + hasInitialized = true; + const isDev = !!msg.isDev; + // let version = msg.version; + const hash = msg.hash; - if (!self.SharedArrayBuffer && !msg.isSharedArrayBufferOverrideEnabled) { - self.postMessage({ - type: 'app-init-failure', - SharedArrayBufferMissing: true, - }); - return; - } + if ( + !self.SharedArrayBuffer && + !msg.isSharedArrayBufferOverrideEnabled + ) { + self.postMessage({ + type: 'app-init-failure', + SharedArrayBufferMissing: true, + }); + return; + } - await importScriptsWithRetry( - `${msg.publicUrl}/kcab/kcab.worker.${hash}.js`, - { maxRetries: isDev ? 5 : 0 }, - ); + await importScriptsWithRetry( + `${msg.publicUrl}/kcab/kcab.worker.${hash}.js`, + { maxRetries: isDev ? 5 : 0 }, + ); - backend.initApp(isDev, self).catch(err => { - console.log(err); - const msg = { - type: 'app-init-failure', - IDBFailure: err.message.includes('indexeddb-failure'), - }; - self.postMessage(msg); + backend.initApp(isDev, self).catch(err => { + console.log(err); + const msg = { + type: 'app-init-failure', + IDBFailure: err.message.includes('indexeddb-failure'), + }; + self.postMessage(msg); - throw err; - }); + throw err; + }); + } } + } catch (error) { + console.log('Failed initializing backend:', error); + self.postMessage({ + type: 'app-init-failure', + BackendInitFailure: true, + }); } }); diff --git a/packages/desktop-client/src/components/FatalError.tsx b/packages/desktop-client/src/components/FatalError.tsx index ec92d7546ea275633739ccbaf55b842eda11056f..e0122a79e263486224904025f31bb8460313d36a 100644 --- a/packages/desktop-client/src/components/FatalError.tsx +++ b/packages/desktop-client/src/components/FatalError.tsx @@ -15,6 +15,7 @@ type AppError = Error & { type?: string; IDBFailure?: boolean; SharedArrayBufferMissing?: boolean; + BackendInitFailure?: boolean; }; type FatalErrorProps = { @@ -64,18 +65,7 @@ function RenderSimple({ error }: RenderSimpleProps) { // user something at least so they aren't looking at a blank // screen msg = ( - <Text> - There was a problem loading the app in this browser version. If this - continues to be a problem, you can{' '} - <Link - variant="external" - linkColor="muted" - to="https://github.com/actualbudget/releases" - > - download the desktop app - </Link> - . - </Text> + <Text>There was a problem loading the app in this browser version.</Text> ); } diff --git a/upcoming-release-notes/2601.md b/upcoming-release-notes/2601.md new file mode 100644 index 0000000000000000000000000000000000000000..dde392e279b87ac18794c1a119b8dead0a8f123d --- /dev/null +++ b/upcoming-release-notes/2601.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [MatissJanis] +--- + +Improved fatal-error handling in case backend failed loading: show error message.