Skip to content
Snippets Groups Projects
Unverified Commit 1a1fe9ac authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:zap: extra error handling in case backend failed loading (#2601)

* :zap: extra error handling in case backend failed loading

* Release notes

* Rename some error vars
parent 16df116d
No related branches found
No related tags found
No related merge requests found
...@@ -12,15 +12,15 @@ let hasInitialized = false; ...@@ -12,15 +12,15 @@ let hasInitialized = false;
const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => { const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => {
try { try {
importScripts(script); importScripts(script);
} catch (e) { } catch (error) {
// Break if maxRetries has exceeded // Break if maxRetries has exceeded
if (maxRetries <= 0) { if (maxRetries <= 0) {
throw e; throw error;
} else { } else {
console.groupCollapsed( console.groupCollapsed(
`Failed to load backend, will retry ${maxRetries} more time(s)`, `Failed to load backend, will retry ${maxRetries} more time(s)`,
); );
console.log(e); console.log(error);
console.groupEnd(); console.groupEnd();
} }
...@@ -36,39 +36,50 @@ const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => { ...@@ -36,39 +36,50 @@ const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => {
} }
}; };
self.addEventListener('message', async e => { self.addEventListener('message', async event => {
if (!hasInitialized) { try {
const msg = e.data; if (!hasInitialized) {
const msg = event.data;
if (msg.type === 'init') { if (msg.type === 'init') {
hasInitialized = true; hasInitialized = true;
const isDev = !!msg.isDev; const isDev = !!msg.isDev;
// let version = msg.version; // let version = msg.version;
const hash = msg.hash; const hash = msg.hash;
if (!self.SharedArrayBuffer && !msg.isSharedArrayBufferOverrideEnabled) { if (
self.postMessage({ !self.SharedArrayBuffer &&
type: 'app-init-failure', !msg.isSharedArrayBufferOverrideEnabled
SharedArrayBufferMissing: true, ) {
}); self.postMessage({
return; type: 'app-init-failure',
} SharedArrayBufferMissing: true,
});
return;
}
await importScriptsWithRetry( await importScriptsWithRetry(
`${msg.publicUrl}/kcab/kcab.worker.${hash}.js`, `${msg.publicUrl}/kcab/kcab.worker.${hash}.js`,
{ maxRetries: isDev ? 5 : 0 }, { maxRetries: isDev ? 5 : 0 },
); );
backend.initApp(isDev, self).catch(err => { backend.initApp(isDev, self).catch(err => {
console.log(err); console.log(err);
const msg = { const msg = {
type: 'app-init-failure', type: 'app-init-failure',
IDBFailure: err.message.includes('indexeddb-failure'), IDBFailure: err.message.includes('indexeddb-failure'),
}; };
self.postMessage(msg); self.postMessage(msg);
throw err; throw err;
}); });
}
} }
} catch (error) {
console.log('Failed initializing backend:', error);
self.postMessage({
type: 'app-init-failure',
BackendInitFailure: true,
});
} }
}); });
...@@ -15,6 +15,7 @@ type AppError = Error & { ...@@ -15,6 +15,7 @@ type AppError = Error & {
type?: string; type?: string;
IDBFailure?: boolean; IDBFailure?: boolean;
SharedArrayBufferMissing?: boolean; SharedArrayBufferMissing?: boolean;
BackendInitFailure?: boolean;
}; };
type FatalErrorProps = { type FatalErrorProps = {
...@@ -64,18 +65,7 @@ function RenderSimple({ error }: RenderSimpleProps) { ...@@ -64,18 +65,7 @@ function RenderSimple({ error }: RenderSimpleProps) {
// user something at least so they aren't looking at a blank // user something at least so they aren't looking at a blank
// screen // screen
msg = ( msg = (
<Text> <Text>There was a problem loading the app in this browser version.</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>
); );
} }
......
---
category: Enhancements
authors: [MatissJanis]
---
Improved fatal-error handling in case backend failed loading: show error message.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment