Result<T, E> — discriminated-union return type for fallible
operations.
Many places in the data layer return T | undefined or T | null
to mean both "missing optional thing" and "real failure" — the
caller can't tell the cases apart, and the error context is lost.
Result makes the distinction explicit:
const r = await store.get(key);
if (isOk(r)) use(r.value);
else if (r.error === 'Missing') skipQuietly();
else surfaceError(r.error);
The error type defaults to string (suitable for tagged unions
like 'Missing' | 'Network' | 'Corrupt') but can be any type —
including a structured error object that carries a cause / stack.
Result<T, E> — discriminated-union return type for fallible operations.
Many places in the data layer return
T | undefinedorT | nullto mean both "missing optional thing" and "real failure" — the caller can't tell the cases apart, and the error context is lost.Resultmakes the distinction explicit:const r = await store.get(key); if (isOk(r)) use(r.value); else if (r.error === 'Missing') skipQuietly(); else surfaceError(r.error);
The error type defaults to
string(suitable for tagged unions like'Missing' | 'Network' | 'Corrupt') but can be any type — including a structured error object that carries a cause / stack.