Skip to content

Commit dc08bd3

Browse files
authored
Merge pull request CloudBotIRC#178 from linuxdaemon/gonzobot+chan-log-error-handling
Handle possible errors in chan_log error logging
2 parents 9c12a82 + 92fddd0 commit dc08bd3

1 file changed

Lines changed: 45 additions & 32 deletions

File tree

plugins/core/chan_log.py

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,48 @@ def _dump_attrs(obj):
1616
def on_hook_end(error, launched_hook, launched_event, admin_log):
1717
should_broadcast = True
1818
if error is not None:
19-
admin_log(
20-
"Error occurred in {}.{}".format(launched_hook.plugin.title, launched_hook.function_name), should_broadcast
21-
)
22-
23-
lines = traceback.format_exception(*error)
24-
last_line = lines[-1]
25-
admin_log(last_line, should_broadcast)
26-
url = web.paste('\n'.join(lines))
27-
admin_log("Traceback: " + url, should_broadcast)
28-
29-
lines = ["{} = {}".format(k, v) for k, v in _dump_attrs(launched_event)]
30-
exc_type, exc, exc_tb = error
31-
32-
lines.append("")
33-
lines.append("Error data:")
34-
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(exc))
35-
36-
if isinstance(exc, RequestException):
37-
if exc.request is not None:
38-
req = exc.request
39-
lines.append("")
40-
lines.append("Request Info:")
41-
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(req))
42-
43-
if exc.response is not None:
44-
response = exc.response
45-
lines.append("")
46-
lines.append("Response Info:")
47-
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(response))
48-
49-
url = web.paste('\n'.join(lines))
50-
admin_log("Event: " + url, should_broadcast)
19+
messages = [
20+
"Error occurred in {}.{}".format(launched_hook.plugin.title, launched_hook.function_name)
21+
]
22+
23+
try:
24+
lines = traceback.format_exception(*error)
25+
last_line = lines[-1]
26+
messages.append(last_line.strip())
27+
except Exception as e:
28+
messages.append("Error occurred while formatting error {}: {}".format(type(e), e))
29+
else:
30+
try:
31+
url = web.paste('\n'.join(lines))
32+
messages.append("Traceback: " + url)
33+
except Exception as e:
34+
messages.append("Error occurred while gathering traceback {}: {}".format(type(e), e))
35+
36+
try:
37+
lines = ["{} = {}".format(k, v) for k, v in _dump_attrs(launched_event)]
38+
exc_type, exc, exc_tb = error
39+
40+
lines.append("")
41+
lines.append("Error data:")
42+
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(exc))
43+
44+
if isinstance(exc, RequestException):
45+
if exc.request is not None:
46+
req = exc.request
47+
lines.append("")
48+
lines.append("Request Info:")
49+
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(req))
50+
51+
if exc.response is not None:
52+
response = exc.response
53+
lines.append("")
54+
lines.append("Response Info:")
55+
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(response))
56+
57+
url = web.paste('\n'.join(lines))
58+
messages.append("Event: " + url)
59+
except Exception as e:
60+
messages.append("Error occurred while gathering error data {}: {}".format(type(e), e))
61+
62+
for message in messages:
63+
admin_log(message, should_broadcast)

0 commit comments

Comments
 (0)