There should be a way to know whether or not a file was loaded, even if the saved table was empty

Right now the sys.load() function seem to always return a table, even if the file failed to load. There should be a clean way of finding out whether or not it was loaded, regardless of the size of the table.
I can somewhat work around it by adding a dummy entry in the table, but it seems a bit counter-intuitive to have to do that every time

On second thought - adding a dummy entry isn’t enough either.

If the file doesn’t load, I want to initialize it and save that file.
But what if there is a file, but it just didn’t load?
In that case, it would overwrite the old one, losing your save data.

Any idea how to solve this?

I’d like to do something like this:

local load_info = sys.load(path)

if load_info.failed then
    print("Load failed. Error: " .. load_info.error)
elseif not load_info.file_found then
    print("No file, create a new one!")
    my_table = {}
    save_file()
else
    print("File loaded!")
    my_table = load_info.table
end

And the same goes for saving, where it will give me info about why it possibly failed to save (permission denied, no room left on storage, etc.), and then whether or not it created a new file

Thanks. We have design work undergoing for how to deal with these types of errors. Not sure when implementation will start but it’s in the backlog.