errors: Stop showing a long list of Nones when there's no request.

This had contributed to making the emails look broken and of uncertain
accuracy.
This commit is contained in:
Greg Price 2017-11-30 14:45:45 -08:00 committed by Steve Howell
parent 68fa29c3ec
commit 77e47900dd
2 changed files with 21 additions and 13 deletions

View File

@ -110,13 +110,16 @@ def zulip_server_error(report: Dict[str, Any]) -> None:
user_info = user_info_str(report) user_info = user_info_str(report)
deployment = deployment_repr() deployment = deployment_repr()
request_repr = ( if report['has_request']:
"Request info:\n~~~~\n" request_repr = (
"- path: %(path)s\n" "Request info:\n~~~~\n"
"- %(method)s: %(data)s\n") % (report) "- path: %(path)s\n"
for field in ["REMOTE_ADDR", "QUERY_STRING", "SERVER_NAME"]: "- %(method)s: %(data)s\n") % (report)
request_repr += "- %s: \"%s\"\n" % (field, report.get(field.lower())) for field in ["REMOTE_ADDR", "QUERY_STRING", "SERVER_NAME"]:
request_repr += "~~~~" request_repr += "- %s: \"%s\"\n" % (field, report.get(field.lower()))
request_repr += "~~~~"
else:
request_repr = "Request info: none"
message = ("Error generated by %s\n\n~~~~ pytb\n%s\n\n~~~~\n%s\n%s" message = ("Error generated by %s\n\n~~~~ pytb\n%s\n\n~~~~\n%s\n%s"
% (user_info, report['stack_trace'], deployment, request_repr)) % (user_info, report['stack_trace'], deployment, request_repr))
@ -131,12 +134,15 @@ def email_server_error(report: Dict[str, Any]) -> None:
user_info = user_info_str(report) user_info = user_info_str(report)
deployment = deployment_repr() deployment = deployment_repr()
request_repr = ( if report['has_request']:
"Request info:\n" request_repr = (
"- path: %(path)s\n" "Request info:\n"
"- %(method)s: %(data)s\n") % (report) "- path: %(path)s\n"
for field in ["REMOTE_ADDR", "QUERY_STRING", "SERVER_NAME"]: "- %(method)s: %(data)s\n") % (report)
request_repr += "- %s: \"%s\"\n" % (field, report.get(field.lower())) for field in ["REMOTE_ADDR", "QUERY_STRING", "SERVER_NAME"]:
request_repr += "- %s: \"%s\"\n" % (field, report.get(field.lower()))
else:
request_repr = "Request info: none\n"
message = ("Error generated by %s\n\n%s\n\n%s\n\n%s" message = ("Error generated by %s\n\n%s\n\n%s\n\n%s"
% (user_info, report['stack_trace'], deployment, request_repr)) % (user_info, report['stack_trace'], deployment, request_repr))

View File

@ -14,6 +14,8 @@ from django.views.debug import ExceptionReporter, get_exception_reporter_filter
from zerver.lib.queue import queue_json_publish from zerver.lib.queue import queue_json_publish
def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None: def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None:
report['has_request'] = True
report['path'] = request.path report['path'] = request.path
report['method'] = request.method report['method'] = request.method
report['remote_addr'] = request.META.get('REMOTE_ADDR', None), report['remote_addr'] = request.META.get('REMOTE_ADDR', None),