From 152cebf33d64d230e5847cbce182dde95c1ac41b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 15 Sep 2016 12:51:27 -0700 Subject: [PATCH] bugdown: Extract log_bugdown_error(). (It makes it easier to mock out the logging.) --- zerver/lib/bugdown/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index 94f301249d..1affd0df51 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -1121,6 +1121,14 @@ current_message = None # type: Optional[Message] # threads themselves, as well. db_data = None # type: Dict[text_type, Any] +def log_bugdown_error(msg): + # type: (str) -> None + """We use this unusual logging approach to log the bugdown error, in + order to prevent AdminZulipHandler from sending the santized + original markdown formatting into another Zulip message, which + could cause an infinite exception loop.""" + logging.getLogger('').error(msg) + def do_convert(md, realm_domain=None, message=None): # type: (markdown.Markdown, Optional[text_type], Optional[Message]) -> Optional[text_type] """Convert Markdown to HTML, with Zulip-specific settings and hacks.""" @@ -1160,7 +1168,7 @@ def do_convert(md, realm_domain=None, message=None): cleaned = _sanitize_for_log(md) # Output error to log as well as sending a zulip and email - logging.getLogger('').error('Exception in Markdown parser: %sInput (sanitized) was: %s' + log_bugdown_error('Exception in Markdown parser: %sInput (sanitized) was: %s' % (traceback.format_exc(), cleaned)) subject = "Markdown parser failure on %s" % (platform.node(),) if settings.ERROR_BOT is not None: