Improve debug state handling and error messaging
If debug=True: - Most plugin methods (if not all) should end the script and report the error to std.out If debug=False: - Plugin methods will log the error, data, and stack trace Future planning: - The debug=False case here has better behavior in my opinion, maybe there's a better way of handling debug=True
This commit is contained in:
parent
c7582a7098
commit
84db35fa6f
2 changed files with 21 additions and 18 deletions
|
@ -146,19 +146,24 @@ class Plugin(object):
|
|||
|
||||
def do(self, function_name, data):
|
||||
if function_name in dir(self.module):
|
||||
# this makes the plugin fail with stack trace in debug mode
|
||||
if self.debug is False:
|
||||
if self.debug is True:
|
||||
# this makes the plugin fail with stack trace in debug mode
|
||||
eval("self.module." + function_name)(data)
|
||||
else:
|
||||
# otherwise we log the exception and carry on
|
||||
try:
|
||||
eval("self.module." + function_name)(data)
|
||||
except:
|
||||
self._dbg("problem in module {} {}".format(function_name, data))
|
||||
else:
|
||||
eval("self.module." + function_name)(data)
|
||||
except Exception:
|
||||
logging.exception("problem in module {} {}".format(function_name, data))
|
||||
if "catch_all" in dir(self.module):
|
||||
try:
|
||||
if self.debug is True:
|
||||
# this makes the plugin fail with stack trace in debug mode
|
||||
self.module.catch_all(data)
|
||||
except:
|
||||
self._dbg("problem in catch all")
|
||||
else:
|
||||
try:
|
||||
self.module.catch_all(data)
|
||||
except Exception:
|
||||
logging.exception("problem in catch all: {} {}".format(self.module, data))
|
||||
|
||||
def do_jobs(self):
|
||||
for job in self.jobs:
|
||||
|
@ -193,15 +198,16 @@ class Job(object):
|
|||
|
||||
def check(self):
|
||||
if self.lastrun + self.interval < time.time():
|
||||
if self.debug is False:
|
||||
if self.debug is True:
|
||||
# this makes the plugin fail with stack trace in debug mode
|
||||
self.function()
|
||||
else:
|
||||
# otherwise we log the exception and carry on
|
||||
try:
|
||||
self.function()
|
||||
except:
|
||||
logging.debug("Problem in job check")
|
||||
else:
|
||||
self.function()
|
||||
except Exception:
|
||||
logging.exception("Problem in job check: {}".format(self.function))
|
||||
self.lastrun = time.time()
|
||||
pass
|
||||
|
||||
|
||||
class UnknownChannel(Exception):
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import logging
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import yaml
|
||||
|
@ -25,5 +24,3 @@ try:
|
|||
bot.start()
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
except:
|
||||
logging.exception('OOPS')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue