river icon indicating copy to clipboard operation
river copied to clipboard

Add `ctx.uncaught` for emitting uncaught errors, particularly in streams

Open Monkatraz opened this issue 7 months ago • 0 comments

Why

Fixes https://github.com/replit/river/issues/333

In streaming procedures, you often need to push an uncaught error into the stream outside of the scope of the handler. This is tricky since all you're left with doing is manually returning an uncaught error rather than using any of the machinery River has built in.

What changed

Added ctx.uncaught which works a lot like ctx.cancel except that it uses UNCAUGHT_ERROR rather than the cancel code. It uses the exact same mechanism as the normal procedure error handler and yields you an error result that you can return if needed. It accepts anything as an argument so that you can use it ergonomically in a try catch.

Versioning

  • [ ] Breaking protocol change
  • [ ] Breaking ts/js API change

Monkatraz avatar Jul 15 '25 18:07 Monkatraz