Error listing a collection in TypeScript with Nakama 3.3.0

Hi, before submitting a bug, I would like to check if I am doing everything right:

  1. Users store data in the same collection:

  1. In the runtime code we would like to fetch that data from all users in the same query (since we don’t know which users have written in that collection). So we pass an empty string as the docs state to the storageList method:
const getInstances: nkruntime.RpcFunction = function (
  ctx: nkruntime.Context,
  logger: nkruntime.Logger,
  nk: nkruntime.Nakama,
  payload: string
) {
  const data = JSON.parse(payload);
  const collection = `island-user-instances_${data.islandId}`;
  const result = nk.storageList("", collection, 10000);

  return JSON.stringify(result);
};

That query fails with the following error:

{"level":"error","ts":"2021-06-28T20:24:13.340Z","caller":"server/runtime_javascript.go:490","msg":"JavaScript runtime function raised an uncaught exception","mode":"rpc","id":"get_instances","error":"TypeError: expects empty or valid user id at github.com/heroiclabs/nakama/v3/server.(*runtimeJavascriptNakamaModule).storageList.func1 (native)"}

If we pass a valid userID on the other hand the query works as expected. We are using the latest Nakama build using docker, locally.

Hey @Leonidas, thank you for this post, I’ve looked into it and it is a bug in the JS runtime, we’ll fix it within the next release of the server.

2 Likes

Hi @sesposito, do you know on which server release this would be addressed? If there is an active issue to follow let me know, many thanks.

@Leonidas the fix is included in the latest release Release v3.4.0 · heroiclabs/nakama · GitHub (sadly the fix is missing from the change log).

Thank you, it worked! One minor issue, when using TypeScript you get a type error if you pass empty (null, empty string '' didn’t work):

  const result = nk.storageList(
    // @ts-ignore
    null,
    collection,
    10000
  );

I had to instruct the compiler to ignore that error.

Thank you for catching this @Leonidas, the nk.storageList TS definition has been updated.

1 Like