GetSortedAsync returning nothing instead of throwing error

In my game, Welcome to Farmtown, I’ve switched datastore schemes halfway through development due to issues with my first implementation.

I have some code that very carefully attempts to load data of the new scheme and checks for errors at every step, but it assumes that if GetSortedAsync() and a subsequent GetCurrentPage() call returns an empty table, then there is no data to load. In this case, it then attempts to load the old scheme.

I also have a macro for Defaultio’s Macros plugin that allows me to view every snapshot of user data in chronological order, so I’m 100% certain I’m getting the correct picture here. I also have an automated report when a DataStore request actually throws an error, so I can say this with absolute certainty: GetSortedAsync()/GetCurrentPage() gave me an empty table for a certain player when they definitely did have data.

My call to GetSortedAsync is as follows:

local success, pages = pcall(function() return playerKeyDatastore:GetSortedAsync(false, 30) end)

If this fails with an error, it bails out, reports it, then kicks the user with a message explaining the problem, that it’s been reported to me, and to try again later.

After that, it does this:

	local success, currentPage = pcall(function() return pages:GetCurrentPage() end)
	if not success then
		warn(currentPage)
		return false, currentPage
	end
	if #currentPage == 0 then
		return true, nil
	end

As you can see, if this call throws an error, it will bail out and kick the user in the same way as before. If it doesn’t throw an error but returns an empty table, it will assume there is no data to load, at which point it will then try to use the old system.

I’m not sure how to work around this at this point. Without an error, my system has absolutely no way of knowing that the request failed, so it must assume there’s no data. Obviously, this causes my players to lose progress when it then attempts to load their old data from before the switch, or gives them entirely new data. If anyone knows of a workaround, please let me know.

1 Like

Still seeing this issue and losing data to it. Not really sure what to do to work around it.