go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

Differentiating between actor state key not found vs. unexpected error

Open cgillum opened this issue 3 years ago • 0 comments

It's not possible to distinguish between a key not being found and an arbitrary error related to state lookups for actors. For example, the following code returns an error:

err := myactor.GetStateManager().Get("bogus", &bytesArray)

The message of the error is "get actor state result empty, with actorType: xxx, actorID: bogus, stateName yyy".

I would like to then be able to write code like this:

if err == ErrKeyNotFound {
    // ... do something for this specific case
} else if err != nil {
    // ... do something generic
}

However, the error returned in this case doesn't allow me to do this without inspecting the contents of the error message, which isn't ideal. Here is the code that generates this specific error: https://github.com/dapr/go-sdk/blob/c89770a47398058f6ea59f54e2065d7dcdaa7beb/actor/state/state_async_provider.go#L52-L54

As shown in my example, it would be great if there was some API or utility that allowed us to distinguish between the key not being found and an unexpected error for actor state lookups (it doesn't have to be my exact example).

cgillum avatar Sep 28 '22 22:09 cgillum