Skip to content
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

Implement error handling and the result type #13

Merged
merged 6 commits into from
Nov 20, 2023
Merged

Implement error handling and the result type #13

merged 6 commits into from
Nov 20, 2023

Conversation

jackyzha0
Copy link
Member

@jackyzha0 jackyzha0 commented Nov 18, 2023

We'd like to have better ergonomics around when requests can fail.

  • Adds the Result<T, E> type. RPC type signature changed from Promise<Output> to Promise<Result<Output, ErrorUnion>> where ErrorUnion is a union of all the declared error types. You can then switch on result.ok to get the Ok or Err cases with appropriate type narrowing.
  • Adds the errors field to a procedure declaration.
  • Returns from a procedure must be a result type. We introduce Ok(payload) and Err(payload) to simplify result construction. Again, both result arms are statically checked so you can't return messages or errors you don't declare in the output and errors fields respectively.
  • Any uncaught exceptions in a handler are caught and wrapped in a result type that matches RiverUncaughtSchema (defined in router/result.ts)
  • Bumps the package version to 0.5.0

@jackyzha0 jackyzha0 requested a review from Monkatraz November 19, 2023 23:07
@bradymadden97 bradymadden97 self-requested a review November 20, 2023 16:40
Copy link
Contributor

@Monkatraz Monkatraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. Jacky already answered some questions I had in Slack.

@jackyzha0 jackyzha0 merged commit f5a149e into main Nov 20, 2023
4 checks passed
@jackyzha0 jackyzha0 deleted the result-type branch November 20, 2023 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants