From 740e84573aaef4e3d087baaf6774f6f3734aa604 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 7 Jun 2026 20:58:17 +0000 Subject: [PATCH] fix: harden error handling and prevent uncaught async rejections - Add null guards to showError/showSuccess so tests and pre-DOM calls don't throw when message elements are absent - Return early from onload when Supabase is not configured so loadPlayers/loadMatches are never called with empty credentials - Surface ELO revert failures to the user via showError instead of silently logging them - Wrap window.recordMatch/recordDoublesMatch/addPlayer with .catch so unhandled promise rejections from HTML onclick attributes are shown https://claude.ai/code/session_01TgxiTLy7fCh5xZPJT8eTVt --- app.js | 8 +++++--- src/ui.js | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 1cfc8ca..54b9f86 100644 --- a/app.js +++ b/app.js @@ -65,9 +65,9 @@ window.clearTeams = clearSelections; window.filterPlayers = filterPlayerList; -window.recordMatch = recordMatch; -window.recordDoublesMatch = recordDoublesMatch; -window.addPlayer = addPlayer; +window.recordMatch = () => recordMatch().catch(err => showError(err.message)); +window.recordDoublesMatch = () => recordDoublesMatch().catch(err => showError(err.message)); +window.addPlayer = () => addPlayer().catch(err => showError(err.message)); // ================= INITIALISIERUNG ================= @@ -81,6 +81,7 @@ window.onload = async function() { if (!_cfg.SUPABASE_URL || !_cfg.SUPABASE_ANON_KEY) { showError('Supabase nicht konfiguriert. Bitte config.js anlegen (siehe config.example.js).'); + return; } await loadPlayers(); @@ -325,6 +326,7 @@ async function saveMatch(match, playerEntries) { await Promise.all(playerEntries.map(({ id }) => updatePlayer(id, state.players[id]))); } catch (revertErr) { console.error('ELO-Revert fehlgeschlagen:', revertErr); + showError('ELO-Synchronisation fehlgeschlagen. Bitte Seite neu laden.'); } showError('Fehler beim Speichern. Match wurde nicht übertragen.'); } finally { diff --git a/src/ui.js b/src/ui.js index d79e9b1..e9d7ff1 100644 --- a/src/ui.js +++ b/src/ui.js @@ -16,6 +16,7 @@ export function getAvatarEmoji(playerId) { export function showError(message) { const el = document.getElementById('errorMessage'); + if (!el) { console.error(message); return; } el.textContent = message; el.style.display = 'block'; setTimeout(() => { el.style.display = 'none'; }, 5000); @@ -23,6 +24,7 @@ export function showError(message) { export function showSuccess(message) { const el = document.getElementById('successMessage'); + if (!el) { console.log(message); return; } el.textContent = message; el.style.display = 'block'; setTimeout(() => { el.style.display = 'none'; }, 5000);