Question regarding error handling of runtime storage api

Hello, I am trying to read multiple items from storage in server runtime code and Im unsure what to expect in terms of return values when only one of the requested reads does not exist. For instance, if I have the following:

reads := *runtime.StorageRead{
{
Collection: “characters”,
Key: charID,
UserID: userID,
},
{
Collection: “quests”,
Key: questID,
UserID: userID,
},
{
Collection: “accepted_quests”,
Key: questID,
UserID: userID,
},
}
acks, err := nk.StorageRead(ctx, reads)
if err != nil {
return “”, fmt.Errorf(“failed to read from datastore: %w”, err)
}

If the third read object was not found in the datbase, but the other two werre, how many items should be returned in the acks list? The StorageObject type doesn’t seem to have any notion of whether or not the entry existed, so I would expect there to only be two items returned, but then would an error be returned?

In general, the documentation around the Go runtime library is rather lacking and it would be nice to at least see some code comments in the interface defintions so we can see what to expect.

Looking at the Nakama code itself, it seems that there would be 2 objects returned and no error. Is that correct?

@jonbonazza We could definitely add more documentation around the Go runtime inside the server. Please open an issue on the docs tracker. All contributions are welcome and I’d be happy to review the work. At some point I’d like to add a small amount of code to autogenerate our function references from the server code stubs themselves for the runtime API.

Looking at the Nakama code itself, it seems that there would be 2 objects returned and no error. Is that correct?

Yes two storage objects would be returned and no error because we don’t treat the lack of existence of a storage object as an error.

1 Like