// What the library detail page's error slot shows after a load. // // Extracted from `/library/[id]/+page.svelte` so it can be unit-tested. export type LoadOutcome = { ok: true } | { ok: false; error: unknown }; /** * The text of whatever a load threw. Backend commands reject with a plain * string, not an `Error`, so reading only `Error.message` replaced every * backend error with the generic fallback and hid what actually failed. */ export function loadErrorMessage(error: unknown): string { if (error instanceof Error && error.message) return error.message; if (typeof error === "string" && error) return error; return "Failed to load item"; } /** * The error to show once a load has ended. * * A success always clears it — a same-item reload used to leave a stale error * up for good. A failed *refresh* of a page already on screen shows none: the * page is still showing what the cache answered, and a background refresh * (reconnect, resume, filter change) must not blank it. Only failing to open an * item leaves the viewer with nothing to see. * * TRACES: UR-062 | DR-297 | UT-267 */ export function errorAfterLoad( outcome: LoadOutcome, options: { refreshing: boolean }, ): string | null { if (outcome.ok || options.refreshing) return null; return loadErrorMessage(outcome.error); }