BUGFIX: Don't spin forever if IDB can't be loaded (#1500)

Our IndexDB handling did not have very good error handling. It wasn't
reporting the actual errors that occured, nor was it using actual Error
objects. In some cases it also had overly convoluted Promise use, and it
didn't need to be .tsx either.

The biggest issue was that if any problem occured during the main
load(), this would end up as an unhandled rejection and so it would only
be logged to the console. This extends the previous catch to also cover
this, so that the recovery screen is activated.
This commit is contained in:
David Walker
2024-07-19 19:27:04 -07:00
committed by GitHub
parent b73816f9db
commit 4502fd443e
3 changed files with 24 additions and 31 deletions

View File

@@ -32,21 +32,18 @@ export function LoadingScreen(): React.ReactElement {
});
useEffect(() => {
load().then(async (saveData) => {
try {
await initSwc();
await Engine.load(saveData);
} catch (error) {
load()
.then((saveData) => Promise.all([initSwc(), Engine.load(saveData)]))
.then(() => {
pushGameReady();
setLoaded(true);
})
.catch(async (error) => {
console.error(error);
ActivateRecoveryMode(error);
await Engine.load("");
setLoaded(true);
return;
}
pushGameReady();
setLoaded(true);
});
});
}, []);
return loaded ? (

View File

@@ -29,7 +29,7 @@ export function DeleteGameButton({ color = "primary" }: IProps): React.ReactElem
pushDisableRestore();
setTimeout(() => location.reload(), 1000);
})
.catch((r) => console.error(`Could not delete game: ${r}`));
.catch((r) => console.error("Could not delete game: %o", r));
}}
open={modalOpened}
onClose={() => setModalOpened(false)}