Checking if an error is retryable?

Hey all,

Is there a way to check if an error coming from .Transact() or .ReadTransact() is retryable in golang?

I’ve found some error predicates[1], but i’m confused by the docs there, how does it return “true”?
I thought the docs imply I should compare it to err.Code, but I can’t find any 5000 error code at all[1].

  1. https://github.com/apple/foundationdb/blob/master/bindings/go/src/fdb/generated.go#L543-L545
  2. https://apple.github.io/foundationdb/api-error-codes.html

The error predicate constants are for use with fdb_error_predicate in the C API. Some bindings expose APIs to use this function, but the Go bindings do not currently.

The best way to check for retryability right now is using OnError. If the error is retryable, the returned future will be set normally. If it isn’t, then the future will be set with the error that is passed in to it.

It should be noted that this function will reset your transaction and possibly inject a delay for backoff purposes.

If you wanted to see which errors are considered retryable, you can look at the implementation of fdb_error_predicate:

And also the mapping of error names to codes: