Check out the Error Handling guide to learn more about how Restate handles transient errors, terminal errors, retries, and timeouts.
Retry strategies
By default, Restate does infinite retries with an exponential backoff strategy. Check out the error handling guide to learn how to customize this.Terminal errors
For failures that should not be retried, return a terminal error. Restate ends the invocation and propagates the error to the caller.TerminalError carries an error code, a message, and optional metadata. Use ToTerminalError to convert an existing error, or use TerminalErrorf to construct one from a formatted message:
The
TerminalError(err) constructor was renamed to ToTerminalError(err). To attach a code, replace TerminalError(err, code) with ToTerminalError(err, WithErrorCode(code)). The previous ErrorCode(err) helper was removed. Use AsTerminalError or AsRetryableError and check for nil before reading the code.AsTerminalError to check and inspect an error. It also finds a terminal error wrapped by another error:
TerminalError directly. Because it implements the standard error interface, you can return it like any other error.
When you return a terminal error, you might need to undo the actions you did earlier in your handler to make sure that your system remains in a consistent state.
Have a look at our sagas guide to learn more.
Retryable errors
Returning a regular Go error already causes Restate to retry. UseRetryableError when you also need to attach a status code to the failure:
ToRetryableError wraps the original error, so errors.Is, errors.As, and errors.Unwrap can still inspect its cause. Use AsRetryableError to access its Restate status code: