fix(import): translate machine-readable import failure reasons

A user whose import died to a worker restart saw the literal string
interrupted_by_restart in the import card — the reconcile writes it as
a machine-readable code, and the card echoed it raw. Classify the two
coded reasons (interrupted_by_restart, the insufficient_memory prefix
from the memory preflight) onto translated, actionable copy across all
six locales; the copy tells the user their data is safe and to upload
the export again, which the re-enabled card already supports. Honest
free-text reasons keep passing through verbatim. Refs #775.
This commit is contained in:
Marc-André Bombeck committed 2026-08-13 06:16:44 +02:00
1 parent 50ff90a409
commit d26bbca52a
8 files changed
+86 -2

No files matched your search

@@ -42,6 +42,24 @@ interface JobStatus {
failureReason: string | null;
}
/**
* Classify a worker `failureReason` for display. The worker writes two
* machine-readable reasons — the reconcile's bare `interrupted_by_restart`
* code and the memory preflight's `insufficient_memory`-prefixed string
* (issue #775) — which must surface as translated, actionable copy
* instead of a raw code. Anything else is honest English free text from
* the parse and passes through verbatim. Exported for the SSR contract
* suite.
*/
export function appleHealthFailureKind(
reason: string | null,
): "interrupted" | "insufficientMemory" | "raw" | null {
if (reason === null || reason.length === 0) return null;
if (reason === "interrupted_by_restart") return "interrupted";
if (reason.startsWith("insufficient_memory")) return "insufficientMemory";
return "raw";
}
export function AppleHealthEstimateWarning({ days }: { days: number }) {
const { t } = useTranslations();
return (
@@ -160,6 +178,23 @@ export function AppleHealthImportCard() {
const isFailed = status?.status === "failed";
const busy = uploading || isRunning;
const percent = status?.progress?.percent ?? null;
const failureText = (() => {
const reason = status?.failureReason ?? null;
switch (appleHealthFailureKind(reason)) {
case "interrupted":
return t(
"settings.sections.export.import.appleHealth.failureInterrupted",
);
case "insufficientMemory":
return t(
"settings.sections.export.import.appleHealth.failureInsufficientMemory",
);
case "raw":
return reason;
default:
return null;
}
})();
const ecg = status?.result?.ecg;
const ecgWritten = (ecg?.imported ?? 0) + (ecg?.updated ?? 0);
@@ -302,7 +337,7 @@ export function AppleHealthImportCard() {
/>
<span>
{uploadError ??
status?.failureReason ??
failureText ??
t("settings.sections.export.import.appleHealth.failed")}
</span>
</p>