Occasionally, the timers fail on my server with this error, but no stack trace:
[CODE]ERROR: Hook 'CheckTimers' Failed: lua/includes/util.lua:184: bad key to string index (number expected, got string)
Removing Hook 'CheckTimers'
[/CODE]
From lua/includes/timers.lua:
[CODE]function Check()
for key, value in pairs( Timer ) do
if ( value.Status == PAUSED ) then
value.Last = CurTime() - value.Diff
elseif ( value.Status == RUNNING && ( value.Last + value.Delay ) <= CurTime() ) then
value.Last = CurTime()
value.n = value.n + 1
if ( value.n >= value.Repetitions && value.Repetitions != 0) then
Stop( key )
end
value.Func()
end
end
-- Run Simple timers
for key, value in pairs( TimerSimple ) do
if ( value.Finish <= CurTime() ) then
table.remove( TimerSimple, key )
value.Func()
end
end
end[/CODE]
The error occurs on: [CODE] for key, value in pairs( TimerSimple ) do[/CODE]
What might be causing this? Which variable was expecting a number but got a string instead? Is there a line I can add to do a stack trace whenever an invalid parameter is inputed?
Would have to see the code that causes this.
Show us all your timers...
It may be caused by putting a timerID as a number or something, or missing an argument.
Means you're trying to index a string with a string, i.e.
[lua]
local mystring = "hi there"
print( mystring[1] ) -- h
print( mystring[ "lol" ] ) -- that error
[/lua]
[editline]28th October 2012[/editline]
Are you sure it's on that line? I can't see how it's possible on that line at all, pairs errors if you try and pass a string instead of a table.
If it was on this line
[lua] if ( value.Finish <= CurTime() ) then[/lua]
It'd make sense if value was a string, i.e. you did timer.Simple( time, string ) somewhere in your code.
Well look at line 184 for yourself in timers.lua
:/
Did something about timers change in GM13?
[QUOTE=infinitywrai;38224187]Well look at line 184 for yourself in timers.lua
:/
Did something about timers change in GM13?[/QUOTE]
OH, It's not that line 184, it's line 184 of includes/util.lua
[editline]28th October 2012[/editline]
[lua]
function IsValid( object )
if ( !object ) then return false end
if ( !object.IsValid ) then return false end -- line 184
return object:IsValid()
end[/lua]
You're calling IsValid on a string.
1) Why is there no stack trace for this?
2) Why did it cause checktimers (and thus all timers) to fail?
[QUOTE=infinitywrai;38224333]1) Why is there no stack trace for this?
2) Why did it cause checktimers (and thus all timers) to fail?[/QUOTE]
Because garry removed pcall from all hooks and timers, meaning if one single hook or timer causes a single error it breaks -everything-
Part of his "fix your errors" initiative.
[editline]28th October 2012[/editline]
Not sure why there wasn't a stack trace though
OK so if I add this line right before line 184 then I should be able to find out exactly what has been causing it? And I can presume timers are failing because some timer is using IsValid wrong?
[code]if type(object) == "string" then ErrorNoHalt("ISVALID BAD CALL") return end[/code]
[QUOTE=infinitywrai;38224461]OK so if I add this line right before line 184 then I should be able to find out exactly what has been causing it? And I can presume timers are failing because some timer is using IsValid wrong?
[code]if type(object) == "string" then ErrorNoHalt("ISVALID BAD CALL") return end[/code][/QUOTE]
print( debug.traceback() ) might work out better then ErrorNoHalt, but yes that should help you find out which timer is fucking up.
Open all your lua files in your text editor, FINDALL>timer.Create & timer.Simple>COPY RESULTS>PASTE HERE
[QUOTE=Remscar;38224784]Open all your lua files in your text editor, FINDALL>timer.Create & timer.Simple>COPY RESULTS>PASTE HERE[/QUOTE]
It might not necessarily be one of his, it could be any addon or even something built in
ok apparently the wiki is wrong ErrorNoHalt does not produce a stack trace. I'll try the print( debug.traceback() ) then
EDIT: Misc question, how do we contribute to the wiki?
Click log in/create account at the top right.
Another misc question: [url]http://wiki.garrysmod.com/page/Global/AddCSLuaFile[/url]
The page says relative to garrysmod/lua, but it seems that in my addons it is relative to the file that calls AddCSLuaFile. Is this a mistake on the wiki?
[QUOTE=infinitywrai;38225657]Another misc question: [url]http://wiki.garrysmod.com/page/Global/AddCSLuaFile[/url]
The page says relative to garrysmod/lua, but it seems that in my addons it is relative to the file that calls AddCSLuaFile. Is this a mistake on the wiki?[/QUOTE]
During the beta AddCSLuaFile was only working relative to garrysmod/lua, it was like that for a good few months when the Wiki was done, I think it was fixed towards the end of the beta and just never corrected on the Wiki.
Kind of weird, previously I had a serverside and a clientside script in /autorun/ and AddCSLuaFile("cs_abc.lua") worked. After I moved my serverside script into /autorun/server/, only AddCSLuaFile("autorun/cs_abc.lua") worked.
Still waiting on reproducing earlier problem with stack trace. Hopefully next update will make this easier to debug: [URL]http://www.facepunch.com/showthread.php?t=1215271&p=38194512&viewfull=1#post38194512[/URL]
[editline]28th October 2012[/editline]
I added this into my util.lua, but the print statements don't seem to go into logs? :(
function IsValid( object ) if ( !object ) then return false end if type(object) == "string" then print("BAD ISVALID CALL!!!") print( debug.traceback() ) ErrorNoHalt("BAD IS VALID CALL v2") return end if ( !object.IsValid ) then return false end return object:IsValid() end
Logs:
[code]L 10/28/2012 - 15:34:59: "[KuKu] Nigulator<21><STEAM_0:1:17996224><Mob boss>" say "/buy Desert eagle"
L 10/28/2012 - 15:35:04: [D:F] Terrorist (STEAM_0:0:28451030) Attempted to switch noclipL 10/28/2012 - 15:35:04: [D:F] Terrorist (STEAM_0:0:28451030) Attempted to switch noclipL 10/28/2012 - 15:35:07: Lua Error: BAD IS VALID CALL v2
L 10/28/2012 - 15:35:07: randomguy12340 (STEAM_0:0:42603531) Spawned a models/hunter/blocks/cube025x025x025.mdlL 10/28/2012 - 15:35:07: [ULX] randomguy12340<STEAM_0:0:42603531> spawned model models/hunter/blocks/cube025x025x025.mdl[/code]
[code]5:35:55: CaSuALtiEs (STEAM_0:0:52689126) Got killed by Code_Red! with a playerL 10/28/2012 - 15:35:55: CaSuALtiEs was killed by Code_Red! with weapon_glock2L 10/28/2012 - 15:35:55: "Urcrau<7><STEAM_0:0:33218839><Gangster>" say "I figured out how to make thrusters invisible"
L 10/28/2012 - 15:35:55: Lua Error: BAD IS VALID CALL v2
L 10/28/2012 - 15:35:55: Nignoggins (STEAM_0:0:9826908) Attempted to switch noclipL 10/28/2012 - 15:35:55: Nignoggins (STEAM_0:0:9826908) Attempted to switch noclipL 10/28/2012 - 15:35:55: Nignoggins (STEAM_0:0:9826908) Attempted to switch noclipL 10/28/2012 - 15:35:55: Nignoggins (STEAM_0:0:9826908) Attempted to switch noclipL 10/28/2012 - 15:35:56: Gdog771 (STEAM_0:1:49916590) Attempted to use tool wire_textscreenL 10/28/2012 - 15:35:57: CaSuALtiEs (STEAM_0:0:52689126) SpawnedL 10/28/2012 - 15:35:58: Gdog771 (STEAM_0:1:49916590) Attempted to use tool wire_textscreenL 10/28/2012 - 15:35:59: Infinity (STEAM_0:0:7623695) Spawned a sent_ballL 10/28/2012 - 15:35:59: [ULX] Infinity<STEAM_0:0:7623695> spawned sent sent_ball[/code]
How am I supposed to debug this? Print statements don't go in logs?
[editline]28th October 2012[/editline]
Should [lua]if type(object) == "string" then error("BAD ISVALID CALL v3", 2) return end[/lua] give me the desired behavior?
OK I got a stacktrace back:
[code]L 10/28/2012 - 18:56:20: stack traceback:
lua/includes/util.lua:184: in function 'IsValid'
gamemodes/darkrp/gamemode/server/gamemode_functions.lua:381: in function 'Func'
lua/includes/modules/timer.lua:190: in function <lua/includes/modules/timer.lua:160>
[C]: in function 'pcall'
addons/ulib/lua/ulib/shared/hook.lua:167: in function <addons/ulib/lua/ulib/shared/hook.lua:145>L 10/28/2012 - 18:56:20: Lua Error: ERROR: Hook 'CheckTimers' Failed: gamemodes/darkrp/gamemode/server/gamemode_functions.lua:381: BAD ISVALID CALL v3
L 10/28/2012 - 18:56:20: Lua Error: Removing Hook 'CheckTimers'[/code]
I looked at the DarkRP code and I'm not sure how killer could become a string considering the if statement?: [URL]https://github.com/FPtje/DarkRP/blob/master/gamemode/server/gamemode_functions.lua#L381[/URL]
[editline]28th October 2012[/editline]
OK I discovered the problem in DarkRP, more details here: [URL]https://github.com/FPtje/DarkRP/issues/46[/URL]
Shame that debugging this was so hard. Why do timer and IsValid errors give no stack trace?
Sorry, you need to Log In to post a reply to this thread.