mirror of https://github.com/zulip/zulip.git
Annotate zilencer.error_notify.
Also fix the annotation of zilencer.views.report_error. The `report` arguments are a Dict containing both strings and the `more_info` sub-dictionary, so we type them as Dict[str, Any]. [tweaked by tabbott]
This commit is contained in:
parent
fe2c352ac0
commit
bd0fd61821
|
@ -1,20 +1,24 @@
|
|||
from __future__ import absolute_import
|
||||
from collections import defaultdict
|
||||
from typing import Any
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.mail import mail_admins
|
||||
|
||||
from zerver.lib.actions import internal_send_message
|
||||
from typing import Dict
|
||||
import six
|
||||
|
||||
def format_subject(subject):
|
||||
# type: (str) -> str
|
||||
"""
|
||||
Escape CR and LF characters.
|
||||
"""
|
||||
return subject.replace('\n', '\\n').replace('\r', '\\r')
|
||||
|
||||
def user_info_str(report):
|
||||
# type: (Dict[str, Any]) -> str
|
||||
if report['user_full_name'] and report['user_email']:
|
||||
user_info = "%(user_full_name)s (%(user_email)s)" % (report)
|
||||
else:
|
||||
|
@ -24,12 +28,14 @@ def user_info_str(report):
|
|||
return user_info
|
||||
|
||||
def notify_browser_error(report):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
report = defaultdict(lambda: None, report)
|
||||
if settings.ERROR_BOT:
|
||||
zulip_browser_error(report)
|
||||
email_browser_error(report)
|
||||
|
||||
def email_browser_error(report):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
subject = "Browser error for %s" % (user_info_str(report))
|
||||
|
||||
body = ("User: %(user_full_name)s <%(user_email)s> on %(deployment)s\n\n"
|
||||
|
@ -51,6 +57,7 @@ def email_browser_error(report):
|
|||
mail_admins(subject, body)
|
||||
|
||||
def zulip_browser_error(report):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
subject = "JS error: %s" % (report['user_email'],)
|
||||
|
||||
user_info = user_info_str(report)
|
||||
|
@ -63,12 +70,14 @@ def zulip_browser_error(report):
|
|||
"stream", "errors", format_subject(subject), body)
|
||||
|
||||
def notify_server_error(report):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
report = defaultdict(lambda: None, report)
|
||||
email_server_error(report)
|
||||
if settings.ERROR_BOT:
|
||||
zulip_server_error(report)
|
||||
|
||||
def zulip_server_error(report):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
subject = '%(node)s: %(message)s' % report
|
||||
stack_trace = report['stack_trace'] or "No stack trace available"
|
||||
|
||||
|
@ -89,6 +98,7 @@ def zulip_server_error(report):
|
|||
user_info, stack_trace, request_repr))
|
||||
|
||||
def email_server_error(report):
|
||||
# type: (Dict[str, Any]) -> None
|
||||
subject = '%(node)s: %(message)s' % (report)
|
||||
|
||||
user_info = user_info_str(report)
|
||||
|
|
|
@ -86,7 +86,7 @@ def submit_feedback(request, deployment, message=REQ(validator=check_dict([]))):
|
|||
|
||||
@has_request_variables
|
||||
def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dict([]))):
|
||||
# type: (HttpRequest, Deployment, str, Dict[str, Optional[str]]) -> HttpResponse
|
||||
# type: (HttpRequest, Deployment, str, Dict[str, Any]) -> HttpResponse
|
||||
report['deployment'] = deployment.name
|
||||
if type == 'browser':
|
||||
notify_browser_error(report)
|
||||
|
|
Loading…
Reference in New Issue