errors: Make Zulip and email paths more parallel.

This helps prevent them from diverging and getting different sets of
features and fixes.  As a bonus, the email path gets a nice tweak that
the Zulip path has had for years, since f7f2ec0ac, which makes the
emails clearer and less broken-looking when logging a message with no
stack trace.
This commit is contained in:
Greg Price 2017-11-30 14:18:16 -08:00 committed by Steve Howell
parent 8c0fd5beaf
commit 68fa29c3ec
3 changed files with 7 additions and 9 deletions

View File

@ -106,7 +106,6 @@ def notify_server_error(report: Dict[str, Any]) -> None:
def zulip_server_error(report: Dict[str, Any]) -> None:
subject = '%(node)s: %(message)s' % (report)
stack_trace = report['stack_trace'] or "No stack trace available"
user_info = user_info_str(report)
deployment = deployment_repr()
@ -115,16 +114,16 @@ def zulip_server_error(report: Dict[str, Any]) -> None:
"Request info:\n~~~~\n"
"- path: %(path)s\n"
"- %(method)s: %(data)s\n") % (report)
for field in ["REMOTE_ADDR", "QUERY_STRING", "SERVER_NAME"]:
request_repr += "- %s: \"%s\"\n" % (field, report.get(field.lower()))
request_repr += "~~~~"
message = ("Error generated by %s\n\n~~~~ pytb\n%s\n\n~~~~\n%s\n%s"
% (user_info, report['stack_trace'], deployment, request_repr))
realm = get_system_bot(settings.ERROR_BOT).realm
internal_send_message(realm, settings.ERROR_BOT,
"stream", "errors", format_subject(subject),
"Error generated by %s\n\n~~~~ pytb\n%s\n\n~~~~\n%s\n%s"
% (user_info, stack_trace, deployment, request_repr))
internal_send_message(realm, settings.ERROR_BOT, "stream", "errors",
format_subject(subject), message)
def email_server_error(report: Dict[str, Any]) -> None:
subject = '%(node)s: %(message)s' % (report)
@ -136,7 +135,6 @@ def email_server_error(report: Dict[str, Any]) -> None:
"Request info:\n"
"- path: %(path)s\n"
"- %(method)s: %(data)s\n") % (report)
for field in ["REMOTE_ADDR", "QUERY_STRING", "SERVER_NAME"]:
request_repr += "- %s: \"%s\"\n" % (field, report.get(field.lower()))

View File

@ -69,11 +69,11 @@ class AdminNotifyHandler(logging.Handler):
report['node'] = platform.node()
report['host'] = platform.node()
stack_trace = None
if record.exc_info:
stack_trace = ''.join(traceback.format_exception(*record.exc_info))
message = str(record.exc_info[1])
else:
stack_trace = 'No stack trace available'
message = record.getMessage()
if '\n' in message:
# Some exception code paths in queue processors

View File

@ -183,7 +183,7 @@ class AdminNotifyHandlerTest(ZulipTestCase):
self.assertIn("host", report)
self.assertIn("user_email", report)
self.assertIn("message", report)
self.assertEqual(report["stack_trace"], None)
self.assertEqual(report["stack_trace"], 'No stack trace available')
# Test arbitrary exceptions from request.user
record.request.user = None # type: ignore # this field is dynamically added