If you work with files and io.open, assert is your best friend
local f,e = io.open("myfile.txt","w")
assert(f,e)
If the program is unable to open the file, you can see the error message description in the logs.
Yggdrasil wrote:If you work with files and io.open, assert is your best friend
local f,e = io.open("myfile.txt","w")
assert(f,e)
If the program is unable to open the file, you can see the error message description in the logs.
Yes, and that is one good approach. I do actually prefer:
MyFile = io.open(CurrPath..'SomeFile.txt', 'w')
if not MyFile then print('Can\'t create file: SomeFile.txt'); return '-1'; end
As not only do I get a very specific (which file?) error in the log, rather than a generic "file or directory doesn't exist", but this also gracefully breaks out of the Update() function in our standard Lua script for Rainmeter, and returns control to the skin. It also returns a value (-1 in this case) that can be tested for in the skin to take some additional action if the file access fails.
You get three values back from io.open, the 3rd one is the error code.
Well, maybe assert is not the proper function, maybe you should rewrite it in application side (overwrite it) to somehow interact with the user, when something goes wrong.
By the way, the error message from io.open contains the file and the path too: