From 16bbba371d8f3d2d3119062e5ba0edb7d4a6b764 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Sun, 26 Jul 2026 13:28:58 +0700 Subject: [PATCH] fix(i18n): show the localized failure message, not the raw browser error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by the Phase 4 adversarial review; three lenses filed it. Every failure path was written `outcome.detail ?? t('...saveFailed')`. But `detail` is set for any rejection that is an Error, which is the normal case for chrome.storage.local.set -- so the `??` almost never fell through and the localized sentence was dead code in all three locales. A Vietnamese user over quota saw "QUOTA_BYTES quota exceeded". The worst instance was legal.saveFailed: "Your acceptance could not be saved, so nothing was recorded. Check that this browser allows extension storage, then try again." Translated into VI and JA, and unreachable -- at the one moment a first-run user most needs an actionable instruction. docs/02 §7 already specified the right shape: "human-readable, localized messages + a copyable technical detail block", which ImportTab has done since Phase 2. The message is now the translated sentence and the raw error moves into a
beside it, in both #settings and the gate. The header controls show the sentence alone -- there is no room for a detail block there, and #settings has one. Co-Authored-By: Claude Opus 5--- src/entrypoints/manager/App.svelte | 12 ++++++-- src/lib/components/LegalGate.svelte | 37 +++++++++++++++++++++---- src/lib/components/SettingsTab.svelte | 40 ++++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/src/entrypoints/manager/App.svelte b/src/entrypoints/manager/App.svelte index a03baf3..ed69973 100644 --- a/src/entrypoints/manager/App.svelte +++ b/src/entrypoints/manager/App.svelte @@ -58,11 +58,17 @@ }; }); - /** Shared by the header controls so a silent failure there is impossible. */ + /** + * Shared by the header controls so a silent failure there is impossible. + * + * The toast carries the LOCALIZED sentence, never the raw browser error — + * `detail` is essentially always present for a storage rejection, so putting + * it first made every translation of settings.saveFailed unreachable. The + * header has no room for a detail block; #settings shows one. + */ function save(patch: Parameters [0]): void { void updateSettings(patch).then((outcome) => { - if (outcome.ok) pushToast(t('settings.saved'), 'success'); - else pushToast(outcome.detail ?? t('settings.saveFailed'), 'danger'); + pushToast(t(outcome.ok ? 'settings.saved' : 'settings.saveFailed'), outcome.ok ? 'success' : 'danger'); }); } diff --git a/src/lib/components/LegalGate.svelte b/src/lib/components/LegalGate.svelte index 25eb565..67bacfa 100644 --- a/src/lib/components/LegalGate.svelte +++ b/src/lib/components/LegalGate.svelte @@ -18,7 +18,8 @@ let checked = $state(false); let saving = $state(false); - let saveError = $state (); + let saveFailed = $state(false); + let saveDetail = $state (); let closeFailed = $state(false); let heading: HTMLHeadingElement | undefined = $state(); let closeTimer: ReturnType | undefined; @@ -35,13 +36,22 @@ function accept(): void { if (!checked || saving) return; saving = true; - saveError = undefined; + saveFailed = false; + saveDetail = undefined; // Timestamp taken at click time and passed down, so the store stays free of // ambient time. Nothing is dismissed until the write resolves. void acceptLegal(new Date().toISOString()).then((outcome) => { saving = false; - if (outcome.ok) onaccepted(); - else saveError = outcome.detail ?? t('legal.saveFailed'); + if (outcome.ok) { + onaccepted(); + return; + } + // The localized recovery sentence is the message; the raw browser error + // is the separate technical detail (docs/02 §7). Showing `detail` in its + // place made legal.saveFailed dead in all three locales — at the one + // moment a first-run user most needs an actionable instruction. + saveFailed = true; + saveDetail = outcome.detail; }); } @@ -95,8 +105,11 @@ {t('legal.accept')} - {#if saveError !== undefined} - {saveError} + {#if saveFailed} +{t('legal.saveFailed')} + {#if saveDetail !== undefined} +{saveDetail}+ {/if} {/if}@@ -169,6 +182,18 @@ font-size: var(--fs-1); } + .detail { + margin: 0; + padding: var(--sp-2); + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: var(--bg); + color: var(--fg-muted); + font-size: var(--fs-0); + white-space: pre-wrap; + overflow-x: auto; + } + .actions { display: flex; gap: var(--sp-2); diff --git a/src/lib/components/SettingsTab.svelte b/src/lib/components/SettingsTab.svelte index 45c5f55..5eaec9e 100644 --- a/src/lib/components/SettingsTab.svelte +++ b/src/lib/components/SettingsTab.svelte @@ -19,6 +19,8 @@ const settings = $derived(getSettings()); let confirmingReset = $state(false); + /** Raw browser error behind the last failed save, if any. */ + let saveDetail = $state(); /** * Every write reports what actually happened. The toast used to be the only @@ -27,8 +29,17 @@ */ function save(patch: Partial , successKey = 'settings.saved'): void { void updateSettings(patch).then((outcome) => { - if (outcome.ok) pushToast(t(successKey), 'success'); - else pushToast(outcome.detail ?? t('settings.saveFailed'), 'danger'); + if (outcome.ok) { + pushToast(t(successKey), 'success'); + saveDetail = undefined; + return; + } + // The LOCALIZED sentence is the message; the raw browser error is the + // separate technical detail docs/02 §7 asks for. Putting `detail` first + // made every translation of settings.saveFailed dead code and showed a + // VI/JA user an untranslated Chrome string. + pushToast(t('settings.saveFailed'), 'danger'); + saveDetail = outcome.detail; }); } @@ -48,8 +59,13 @@ function confirmReset(): void { confirmingReset = false; void resetSettings().then((outcome) => { - if (outcome.ok) pushToast(t('settings.resetDone'), 'success'); - else pushToast(outcome.detail ?? t('settings.saveFailed'), 'danger'); + if (outcome.ok) { + pushToast(t('settings.resetDone'), 'success'); + saveDetail = undefined; + return; + } + pushToast(t('settings.saveFailed'), 'danger'); + saveDetail = outcome.detail; }); } @@ -139,6 +155,10 @@ {/snippet} + {#if saveDetail !== undefined} + {saveDetail}+ {/if} + @@ -178,6 +198,18 @@ border-color: var(--accent); } + .detail { + margin: var(--sp-3) 0 0; + padding: var(--sp-2); + border: 1px solid var(--border); + border-radius: var(--radius-sm); + background: var(--bg-raised); + color: var(--fg-muted); + font-size: var(--fs-0); + white-space: pre-wrap; + overflow-x: auto; + } + footer { padding-top: var(--sp-4); }