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):
|
def do(self, function_name, data):
|
||||||
if function_name in dir(self.module):
|
if function_name in dir(self.module):
|
||||||
# this makes the plugin fail with stack trace in debug mode
|
if self.debug is True:
|
||||||
if self.debug is False:
|
# 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:
|
try:
|
||||||
eval("self.module." + function_name)(data)
|
eval("self.module." + function_name)(data)
|
||||||
except:
|
except Exception:
|
||||||
self._dbg("problem in module {} {}".format(function_name, data))
|
logging.exception("problem in module {} {}".format(function_name, data))
|
||||||
else:
|
|
||||||
eval("self.module." + function_name)(data)
|
|
||||||
if "catch_all" in dir(self.module):
|
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)
|
self.module.catch_all(data)
|
||||||
except:
|
else:
|
||||||
self._dbg("problem in catch all")
|
try:
|
||||||
|
self.module.catch_all(data)
|
||||||
|
except Exception:
|
||||||
|
logging.exception("problem in catch all: {} {}".format(self.module, data))
|
||||||
|
|
||||||
def do_jobs(self):
|
def do_jobs(self):
|
||||||
for job in self.jobs:
|
for job in self.jobs:
|
||||||
|
|
@ -193,15 +198,16 @@ class Job(object):
|
||||||
|
|
||||||
def check(self):
|
def check(self):
|
||||||
if self.lastrun + self.interval < time.time():
|
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:
|
try:
|
||||||
self.function()
|
self.function()
|
||||||
except:
|
except Exception:
|
||||||
logging.debug("Problem in job check")
|
logging.exception("Problem in job check: {}".format(self.function))
|
||||||
else:
|
|
||||||
self.function()
|
|
||||||
self.lastrun = time.time()
|
self.lastrun = time.time()
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class UnknownChannel(Exception):
|
class UnknownChannel(Exception):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sys
|
import sys
|
||||||
import logging
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
@ -25,5 +24,3 @@ try:
|
||||||
bot.start()
|
bot.start()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except:
|
|
||||||
logging.exception('OOPS')
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue