From b67b9efc3122fa0056f0a2766223034938420ae2 Mon Sep 17 00:00:00 2001 From: neverblde Date: Mon, 29 Apr 2024 23:23:00 -0700 Subject: [PATCH] Catch errors and rejected promises. --- src/battle-scene.ts | 2 ++ src/main.ts | 15 +++++++++++++++ src/phases.ts | 2 ++ src/ui/daily-run-scoreboard.ts | 2 +- src/ui/title-ui-handler.ts | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 6b54505b6a1..1201ed12d43 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -889,6 +889,8 @@ export default class BattleScene extends SceneBase { let battleConfig: FixedBattleConfig = null; + throw new Error('JLIN not implemented.'); + this.resetSeed(newWaveIndex); const playerField = this.getPlayerField(); diff --git a/src/main.ts b/src/main.ts index 6a00693fc71..973f57fda37 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,21 @@ import BBCodeText from 'phaser3-rex-plugins/plugins/bbcodetext'; import TransitionImagePackPlugin from 'phaser3-rex-plugins/templates/transitionimagepack/transitionimagepack-plugin.js'; import { LoadingScene } from './loading-scene'; + +// Catch global errors and display them in an alert so users can report the issue. +window.onerror = function (message, source, lineno, colno, error) { + console.error(error); + let errorString = `Received unhandled error. Open browser console and click OK to see details.\nError: ${message}\nSource: ${source}\nLine: ${lineno}\nColumn: ${colno}\nStack: ${error.stack}`; + alert(errorString); + // Avoids logging the error a second time. + return true; +}; + +window.addEventListener('unhandledrejection', (event) => { + let errorString = `Received unhandled promise rejection. Open browser console and click OK to see details.\nReason: ${event.reason}`; + alert(errorString); + }); + const config: Phaser.Types.Core.GameConfig = { type: Phaser.WEBGL, parent: 'app', diff --git a/src/phases.ts b/src/phases.ts index 1393355e3f5..70351e91682 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -330,6 +330,8 @@ export class TitlePhase extends Phase { this.scene.sessionPlayTime = 0; this.end(); }); + }).catch(err => { + console.error("Failed to load daily run:\n", err); }); }); } diff --git a/src/ui/daily-run-scoreboard.ts b/src/ui/daily-run-scoreboard.ts index 90fef5ba5e4..94654692e8c 100644 --- a/src/ui/daily-run-scoreboard.ts +++ b/src/ui/daily-run-scoreboard.ts @@ -165,7 +165,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { } else this.loadingLabel.setText('No Rankings'); }); - }); + }).catch(err => { console.error("Failed to load daily rankings:\n", err) }); } } diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts index 6c96e475929..d30c3efdab5 100644 --- a/src/ui/title-ui-handler.ts +++ b/src/ui/title-ui-handler.ts @@ -64,6 +64,9 @@ export default class TitleUiHandler extends OptionSelectUiHandler { this.playerCountLabel.setText(`${stats.playerCount} Players Online`); if (this.splashMessage === battleCountSplashMessage) this.splashMessageText.setText(battleCountSplashMessage.replace('{COUNT}', stats.battleCount.toLocaleString('en-US'))); + }) + .catch(err => { + console.error("Failed to fetch title stats:\n", err); }); }