VIP-75: Concise tagged catch (e catch { when ... })
Status: accepted 2026-11-27 (language ergonomics wave — extending VIP-5 catch with VIP-7 when arms).
Decision
Add a zero-ambiguity block-arm form of catch expressions that reuses VIP-7 when / default arms directly after catch:
const user = users.find(id) catch { when UserNotFound: guest }
const val = fetchItem(id) catch {
when NotFound: "missing";
when RateLimited(let e): try sleep(e.retryAfter), "retry";
}Syntax
- Immediately after
catch,{followed bywhen <pattern>(notwhen:) ordefault:begins a tagged catch handler (ClosedCatchHandler). - Ordinary object literals after
catch(e catch { a: 1 },e catch { when: 1 },e catch {}) remain invalid handlers and continue to reportEK0509. - Arms reuse VIP-7
when <pattern>: <armBody>anddefault: <armBody>grammar (including error classeswhen NotFound, error extractorswhen RateLimited(let e), object tag patternswhen { _tag: "NotFound", let id }, guards,and/or/not, comma expressions,try, andthrow). - Multiple arms are separated by
;; a trailing;before the closing}is optional (so single-arme catch { when NotFound: guest }needs no semicolon). - As a closed catch handler,
catch { ... }follows VIP-5 precedence rules: unparenthesized mixing with??,||,&&or postfix/binary continuations on the same line reportEK0512, and ASI starts a new statement after}on a new line.
Semantics & Lowering
e catch { when P1: v1; when P2: v2 } has the exact semantics of:
e catch effect ($err) => match ($err) {
when P1: v1;
when P2: v2;
default: throw $err;
}And with an explicit default: vd arm:
e catch effect ($err) => match ($err) {
when P1: v1;
default: vd;
}- Effectful arm bodies: Arm bodies evaluate in effect context, so
tryruns Effects andthrowfails typed without writingeffect (err) => .... - Automatic residual rethrow & narrowing: When no
default:arm is present, unmatched errors are automatically rethrown with their flow-narrowed residual type, mirroringEffect.catchTag/Effect.catchTags. Matching every member ofEnarrows the residual error channel tonever; leaving a member unhandled preserves it inE(and triggersEK9201if excluded by a declared return contract). - Explicit
default:arm: Handles all remaining errors, narrowing residualEtonever(unless an arm throws or runs a failing Effect). - Context & head rules: All VIP-5 rules apply unchanged (
EK0504outside effect code,EK0505fortry e catch { ... },EK0506for non-Effect operand,EK9204warning whenecannot fail,EK2114inside a hatch).
Motivation
Before VIP-75, catching a single error tag required e catch effect (err) => match (err) { when NotFound: guest; default: throw err; }, which was longer than Effect TypeScript's e.pipe(Effect.catchTag("NotFound", () => Effect.succeed(guest))). In real providers such as Alchemy's RegistryPolicy, catch was the single remaining place where VibeLang was more verbose than Effect TypeScript. e catch { when ... } eliminates the ceremony while supporting full VIP-7 pattern matching, multi-tag recovery, extractor bindings, effectful recovery arms, and exact residual error narrowing.