fix(i18n): show the localized failure message, not the raw browser error
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 <pre class="detail"> 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 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+76
-13
No files matched your search
@@ -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<typeof updateSettings>[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');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
let checked = $state(false);
|
||||
let saving = $state(false);
|
||||
let saveError = $state<string | undefined>();
|
||||
let saveFailed = $state(false);
|
||||
let saveDetail = $state<string | undefined>();
|
||||
let closeFailed = $state(false);
|
||||
let heading: HTMLHeadingElement | undefined = $state();
|
||||
let closeTimer: ReturnType<typeof setTimeout> | 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 @@
|
||||
<span>{t('legal.accept')}</span>
|
||||
</label>
|
||||
|
||||
{#if saveError !== undefined}
|
||||
<Callout tone="danger">{saveError}</Callout>
|
||||
{#if saveFailed}
|
||||
<Callout tone="danger">{t('legal.saveFailed')}</Callout>
|
||||
{#if saveDetail !== undefined}
|
||||
<pre class="detail">{saveDetail}</pre>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<div class="actions">
|
||||
@@ -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);
|
||||
|
||||
@@ -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<string | undefined>();
|
||||
|
||||
/**
|
||||
* Every write reports what actually happened. The toast used to be the only
|
||||
@@ -27,8 +29,17 @@
|
||||
*/
|
||||
function save(patch: Partial<Settings>, 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;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@@ -139,6 +155,10 @@
|
||||
{/snippet}
|
||||
</SettingRow>
|
||||
|
||||
{#if saveDetail !== undefined}
|
||||
<pre class="detail">{saveDetail}</pre>
|
||||
{/if}
|
||||
|
||||
<footer>
|
||||
<Button onclick={() => (confirmingReset = true)}>{t('settings.reset')}</Button>
|
||||
</footer>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user