-
Notifications
You must be signed in to change notification settings - Fork 10
Add ctx.uncaught
for emitting uncaught errors, particularly in streams
#335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cancel: (message?: string) => ErrResult<Static<typeof CancelErrorSchema>>; | ||
/** | ||
* This emits an uncaught error in the same way that throwing an error in a handler | ||
* would. You should minimize the amount of work you do after calling this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can create an eslint rule for this
/** | ||
* This emits an uncaught error in the same way that throwing an error in a handler | ||
* would. You should minimize the amount of work you do after calling this function | ||
* as this will start a cleanup of the entire procedure call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe clarify this ends the readable/writables
* You'll typically want to use this for streaming procedures, as in e.g. an RPC | ||
* you can just throw instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* You'll typically want to use this for streaming procedures, as in e.g. an RPC | |
* you can just throw instead. | |
* You'll typically want to use this for server-sent stream procedures like subscriptions or streams which may handle things inside closures where throwing will not be caught by River's procedure uncaught handler. |
* You'll typically want to use this for streaming procedures, as in e.g. an RPC | ||
* you can just throw instead. | ||
*/ | ||
uncaught: (err?: unknown) => ErrResult<Static<typeof UncaughtErrorSchema>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does it mean to throw an uncaught with no err?
Why
Fixes #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 likectx.cancel
except that it usesUNCAUGHT_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