Skip to content

Error Handling

Chris O'Hara edited this page Jul 2, 2024 · 2 revisions

When executing functions, Dispatch automatically detects whether it needs to retry a failing function call or not.

It does this by automatically categorizing errors into one of the standard dispatchproto.Status codes. The status codes instruct the Dispatch cloud service about whether it needs to retry a failing function call, and/or whether/how it needs to adjust the execution concurrency.

Manually categorizing errors

If Dispatch is not categorizing errors correctly for a specific use case, or more control is desired, functions can return one of the built-in error instances which correspond to a Status: https://github.com/dispatchrun/dispatch-go/blob/main/error.go.

For example, to instruct Dispatch that an error was related to throttling, use:

sendEvent := dispatch.Func("sendEvent", func (ctx context.Context, event string) (any, error) {
    result, err := someSDK.SendEvent(event)
    if err != nil {
        // Manually categorize the error as being related to throttling.
        return fmt.Errorf("%w: %v", dispatch.ErrThrottled, err)
    }
    // ...
})

Dispatch will retry these function calls when an error occurs, and will adjust the execution concurrency accordingly.

Clone this wiki locally