There is a thing called a "protected call" (pcall) which you can use here. This is an example plugin:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Failed_Plugin_Test"
author="Nick Gammon"
id="35cdfbf0c4bd7c0c58409408"
language="Lua"
purpose="testing auto-disable plugins"
date_written="2018-07-10 08:35:14"
requires="5.06"
version="1.0"
>
</plugin>
<!-- Timers -->
<timers>
<timer enabled="y"
second="3.00"
name="periodic_timer"
send_to="12"
>
<send>
local function protected_timer_function ()
print "timer test"
error "plugin error"
end -- function protected_call
ok, result = pcall (protected_timer_function)
if ok then
return
end -- if ok
-- disable this timer (or the plugin if you want)
EnableTimer ("periodic_timer", false)
-- show the error
error (result)
</send>
</timer>
</timers>
</muclient>
In this case I have a timer that fires every 3 seconds, however it has an error in it: error "plugin error"
It is called by the timer with a "pcall" which can detect if there was an error in that function (or any function that it calls). If so, the "ok" result is nil, and we can use that to detect that an error occurred, and then disable the timer (or you could disable the entire plugin) so as to reduce spam.