-
Notifications
You must be signed in to change notification settings - Fork 7
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
SDK documentation on error handling #122
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
--- | ||
sidebar_position: 8 | ||
description: "Restate's retry strategy and how to manage it from the SDK." | ||
draft: true | ||
--- | ||
|
||
# Error handling | ||
# Error handling | ||
|
||
Restate takes care of retries of failed invocations. | ||
It does this for all kinds of errors, such as transient network errors and errors thrown inside handlers. | ||
By default, Restate does infinite retries with an exponential backoff strategy. | ||
|
||
For situations where you do not want the invocation to be retried, but instead you want the error message | ||
to be propagated back to the caller, you can use a `terminal error`. | ||
|
||
```typescript | ||
import { TerminalError } from "@restatedev/restate-sdk"; | ||
|
||
// Inside your handler throw terminal errors via: | ||
throw new TerminalError("Something went wrong.", { errorCode: 13, cause: "Something caused this." }) | ||
``` | ||
|
||
The `errorCode` and `cause` are optional. You can throw a terminal error anywhere in your handler. | ||
Restate will propagate the error code and message back to the caller and will consider this invocation to be finished. | ||
|
||
## Errors during side effect execution | ||
|
||
Throwing errors inside a side effect has the same semantics as anywhere else in your handler code. | ||
By default, Restate infinitely retries the invocation, and therefore the side effect. | ||
Errors that should not be retried, should be thrown as terminal errors, as described earlier. | ||
|
||
Invocation retries are triggered by Restate, not by the SDKs. | ||
For some use cases, you may want to do the side effect retries from within the invocation, | ||
because this is faster and more efficient in certain scenarios (e.g. you have a connection set up to an external system or database). | ||
Have a look at the [side effect documentation](https://docs.restate.dev/services/sdk/side-effects#retrying-on-failure) | ||
on how to set this up. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we expose the error codes as an enum from the SDK?
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.
Right, we indeed expose those 👍 I will adapt it
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.
Hmm the only ones we expose are: internal, journal_mismatch and protocol_violation... Maybe that is not really worth exposing or documenting? Since journal mismatch and protocol violations are not something the user code detects
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.
Yes, we shouldn't expose journal_mismatch or protocol_violation to the user. Maybe at some point we want to expose something like an
UserErrorCode
that is aligned with https://github.com/restatedev/restate/blob/ebf084cdfa2639e192911d90394fdcc0168eeefe/src/types/src/errors.rs#L21 in case users want to use error codes across SDKs. Then let's leave it as is for now.