It is currently April 28th, 2024, 4:22 pm

Lua error handling

Report bugs with the Rainmeter application and suggest features.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Lua error handling

Post by MerlinTheRed »

Perhaps you've noticed that sometimes when you try to run a Lua script with some invalid code (Like using SKIN.Bang() instead of SKIN:Bang(), Rainmeter will crash completely. I find this a little annoying since it makes debugging the Lua code much more time-consuming.

Is there a way we could get crashed Lua scripts to exit gracefully, write something to the log and return some error code, disable the script measure or whatever else seems reasonable? That way you don't have to restart Rainmeter all the time while figuring out what went wrong.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Lua error handling

Post by KreAch3R »

+1 to that. :)
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Lua error handling

Post by Kaelri »

Most Lua errors do print a message to the log, terminate the script, and allow the rest of the skin to continue running without it. In my experience, errors that actually crash Rainmeter are uncommon (though not rare), and we usually have to track them down on a case-by-case basis. I'll see if there's an answer about that SKIN.Bang issue.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Lua error handling

Post by KreAch3R »

I am talking about the real messed-up stuff, that Rainmeter just hangs up and requires a restart. :p I think that happens if I mis-write an if or for statement and get into infinite loops (don't take my word for it, most of the times I didn't use a function correctly or I had a typo). In these cases, Rainmeter is able to produce the log output (telling me in which line the error occured etc), and then the "Rainmeter has crashed" window appears. Could somehow Rainmeter recover from it and completely exit the script or is the nature of the problem itself (stuck in the infinity) the same reason Rainmeter can't exit it?
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Lua error handling

Post by MerlinTheRed »

Kaelri wrote:Most Lua errors do print a message to the log, terminate the script, and allow the rest of the skin to continue running without it. In my experience, errors that actually crash Rainmeter are uncommon (though not rare), and we usually have to track them down on a case-by-case basis. I'll see if there's an answer about that SKIN.Bang issue.
As far as I remember it happens with every field I try to access that doesn't exist (i.e. doing name.field on a variable that doesn't have "field").
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: Lua error handling

Post by ~Faradey~ »

in case you don't know...

When Rainmeter starts it's clears log file. So when rainmeter crashes, close or terminate rainmeter.exe from task manager and before launch it again, go to "%HomeDrive%:\Users\%UserName%\AppData\Roaming\Rainmeter" and there should be a log-file "Rainmeter.log", where you will be able to spot your error...
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Lua error handling

Post by MerlinTheRed »

Thank you. I didn't know the log was cleared. Still I'd like to have a more graceful behavior. Can't you catch all exceptions or something when calling the Lua library? Or does it not throw exceptions? If the library itself crashes, that would be bad, but I think such a popular extension language must surely also contain proper error handling.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Lua error handling

Post by poiru »

MerlinTheRed wrote:Perhaps you've noticed that sometimes when you try to run a Lua script with some invalid code (Like using SKIN.Bang() instead of SKIN:Bang(), Rainmeter will crash completely. I find this a little annoying since it makes debugging the Lua code much more time-consuming.
Most of the time, Lua scripts will fail gracefully. The reason that specific case crashes is because SKIN:Bang('!Bang') is just syntactic sugar for SKIN.Bang(SKIN, '!Bang'). With SKIN.Bang('!Bang'), the first parameter is not what is expected (the SKIN object), so Rainmeter crashes. That said, I do agree that this should be fixed. I'll take care of it when I get some time.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Lua error handling

Post by MerlinTheRed »

Oh, so in this case the error is on the Rainmeter side. Well, that changes things ;)
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!