Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Plugins
➜ Disable on Error
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Rene
(46 posts) Bio
|
| Date
| Sun 08 Jul 2018 05:48 PM (UTC) |
| Message
| Is there a way to make a plugin automatically disable itself on an error? I find ones with timers get insanely spammy when they error if it is updating frequently until you get a chance to manually disable it, is there some internal way to detect if it has an error and disable itself?
Thanks. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Mon 09 Jul 2018 07:03 AM (UTC) |
| Message
| | What do you mean by "an error"? A script error? Do you have your scripts in "send to script" or a script file? I think you'll find that if you use a script file the plugin gets automatically disabled when an error is raised. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Rene
(46 posts) Bio
|
| Date
| Reply #2 on Mon 09 Jul 2018 07:32 PM (UTC) |
| Message
| I meant a script error in a plugin.
I find that if that function is called again like by a tic timer it will keep displaying that the function had a previous error and can be real spammy, is there a way to just have it disable the plugin? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Mon 09 Jul 2018 09:45 PM (UTC) |
| Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
15,011 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top