Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit 84db35f

Browse files
author
Jeff Ammons
committed
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
1 parent c7582a7 commit 84db35f

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

rtmbot/core.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,24 @@ def register_jobs(self):
146146

147147
def do(self, function_name, data):
148148
if function_name in dir(self.module):
149-
# this makes the plugin fail with stack trace in debug mode
150-
if self.debug is False:
149+
if self.debug is True:
150+
# this makes the plugin fail with stack trace in debug mode
151+
eval("self.module." + function_name)(data)
152+
else:
153+
# otherwise we log the exception and carry on
151154
try:
152155
eval("self.module." + function_name)(data)
153-
except:
154-
self._dbg("problem in module {} {}".format(function_name, data))
155-
else:
156-
eval("self.module." + function_name)(data)
156+
except Exception:
157+
logging.exception("problem in module {} {}".format(function_name, data))
157158
if "catch_all" in dir(self.module):
158-
try:
159+
if self.debug is True:
160+
# this makes the plugin fail with stack trace in debug mode
159161
self.module.catch_all(data)
160-
except:
161-
self._dbg("problem in catch all")
162+
else:
163+
try:
164+
self.module.catch_all(data)
165+
except Exception:
166+
logging.exception("problem in catch all: {} {}".format(self.module, data))
162167

163168
def do_jobs(self):
164169
for job in self.jobs:
@@ -193,15 +198,16 @@ def __repr__(self):
193198

194199
def check(self):
195200
if self.lastrun + self.interval < time.time():
196-
if self.debug is False:
201+
if self.debug is True:
202+
# this makes the plugin fail with stack trace in debug mode
203+
self.function()
204+
else:
205+
# otherwise we log the exception and carry on
197206
try:
198207
self.function()
199-
except:
200-
logging.debug("Problem in job check")
201-
else:
202-
self.function()
208+
except Exception:
209+
logging.exception("Problem in job check: {}".format(self.function))
203210
self.lastrun = time.time()
204-
pass
205211

206212

207213
class UnknownChannel(Exception):

start_rtmbot.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
22
import sys
3-
import logging
43
from argparse import ArgumentParser
54

65
import yaml
@@ -25,5 +24,3 @@ def parse_args():
2524
bot.start()
2625
except KeyboardInterrupt:
2726
sys.exit(0)
28-
except:
29-
logging.exception('OOPS')

0 commit comments

Comments
 (0)