A timer callback's exception outside a test runner fails the run
Date: 2026-11-29
Area: runtime, engine
Refines: ADR 0113's "The queue parks it and the runner attributes it
to the test that scheduled it", which now holds only while a test runner attributes errors; ADR 0113's other decisions
stand.
Related: ADR 0124, Errors,
Testing API, #2372,
#2241
Context
ADR 0113 keeps a real-mode timer callback's exception away from whatever frame was awaiting: raising it at the wait
made it catchable by an unrelated try and left the awaited promise pending. The queue parks the first exception, and
the test runner reads it after the test body and fails the test that scheduled the timer.
The queue parked it in every host, not only under a test runner. Outside one nothing read it back, so the exception
vanished: GocciaREPL printed nothing for setTimeout(() => { throw new Error("x") }, 0), an embedder's Run
returned Ok, and GocciaRunner, which exposes no timer globals, exited 0 when an AbortSignal.timeout listener
threw. A throwing queued callback (queueMicrotask) in the same hosts already ends the run as an uncaught error,
unless a test runner attributes it to a unit (Goccia.Promise JobErrorsToHost).
Node prints an exception that reaches its event loop and exits with code 1 (Node.js process documentation, event
'uncaughtException'). Node v26.13.0 runs no other pending timer after the first throw. Bun v1.4.4 prints it, runs the
remaining timers and then exits 1.
Decision
Johannes decided this on 2026-11-29 ("Agreed"): in GocciaRunner and host programs a timer callback's exception is
reported as an uncaught error and fails the run with exit 1, as Node and Bun do; the REPL reports it and keeps running,
as it does for a line that fails.
- The event loop passes
fireNextwhether a test runner attributes errors (JobErrorsToHost). While one does, the queue parks the exception as ADR 0113 describes. Otherwise it propagates out of the event loop, which is the host's frame and not the script's, so notryin the script catches it. Runthen fails with it as with any uncaught error: its name, text and the location where it was thrown, and no completion value. The failed run takes the work still pending with it (#2241), so no later timer runs. That matches Node, which exits at the first one.GocciaRunnerprints it and exits 1.GocciaREPLreports it where it reports a failing line and reads the next one.GocciaTestRunnerandgoccia:test'srunTestskeep failing the test that scheduled the timer.
Consequences
- One rule covers queued callbacks and timer callbacks: their exception is attributed to a test while a test runner runs, and is an uncaught error everywhere else.
- A REPL line whose timer throws reports the timer's error instead of its value, as a line whose microtask throws does.
- Fake timers are unchanged: their advances rethrow at the call that moved the clock.
- Both the REPL and the runner keep printing uncaught errors where they print them today, on standard output.