From 3ee19e736af806c3bec1755026d30061d43fc0e7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 30 2016 15:34:05 +0000 Subject: [PATCH 1/2] Allow setting a logger to be used in pagure.lib This way we use a central logger when a known configuration --- diff --git a/pagure/__init__.py b/pagure/__init__.py index 3bcfd4e..c2433a0 100644 --- a/pagure/__init__.py +++ b/pagure/__init__.py @@ -190,6 +190,7 @@ APP.logger.addHandler(SHANDLER) LOG = APP.logger LOG.setLevel(APP.config.get('LOG_LEVEL', 'INFO')) +pagure.lib.set_log(LOG) APP.wsgi_app = pagure.proxy.ReverseProxied(APP.wsgi_app) diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 1d1bd37..41d2a45 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -21,6 +21,7 @@ except ImportError: import json import datetime +import logging import markdown import os import shutil @@ -53,6 +54,7 @@ from pagure.lib import model REDIS = None PAGURE_CI = None +LOG = None def set_redis(host, port, dbname): @@ -68,6 +70,12 @@ def set_pagure_ci(services): PAGURE_CI = services +def set_log(logger): + """ Set a logger that can be used in this module. """ + global LOG + LOG = logger + + def get_user(session, key): """ Searches for a user in the database for a given username or email. """ From 96b4f596407d6ab94ccc8b7c49183777d5018223 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 30 2016 15:34:05 +0000 Subject: [PATCH 2/2] Be tolerant to markdown processing error Sometime a markdown is wrongly formatted and this will raise an error with this change we default to sending back the cleaned but unformatted text but log the error so admins are aware of it (not sure what they can do but we'll see, if it gets annoying we can always reconsider). --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 41d2a45..540b1ec 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2923,7 +2923,12 @@ def text2markdown(text, extended=True): ) if text: - return clean_input(md_processor.convert(text)) + try: + text = md_processor.convert(text) + except Exception as err: + LOG.exception( + 'A markdown error occured while processing: ``%s``' % text) + return clean_input(text) return ''