mirror of https://github.com/zulip/zulip.git
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:
parent
8c0fd5beaf
commit
68fa29c3ec
|
@ -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()))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue