From a8afe5ed17ca49cf68b25932a73ca628552ddd6c Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Fri, 27 Jul 2012 15:58:55 -0400 Subject: [PATCH] Change modulestore to use a logging error handler * log errors, but don't fail --- common/lib/xmodule/xmodule/errorhandlers.py | 24 +++++++++++++++++-- common/lib/xmodule/xmodule/modulestore/xml.py | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/errorhandlers.py b/common/lib/xmodule/xmodule/errorhandlers.py index 6840d9ff74..0f97377b2a 100644 --- a/common/lib/xmodule/xmodule/errorhandlers.py +++ b/common/lib/xmodule/xmodule/errorhandlers.py @@ -1,5 +1,12 @@ +import logging import sys +log = logging.getLogger(__name__) + +def in_exception_handler(): + '''Is there an active exception?''' + return sys.exc_info() != (None, None, None) + def strict_error_handler(msg, exc_info=None): ''' Do not let errors pass. If exc_info is not None, ignore msg, and just @@ -11,13 +18,26 @@ def strict_error_handler(msg, exc_info=None): if exc_info is not None: raise exc_info[0], exc_info[1], exc_info[2] - # Check if there is an exception being handled somewhere up the stack - if sys.exc_info() != (None, None, None): + if in_exception_handler(): raise raise Exception(msg) +def logging_error_handler(msg, exc_info=None): + '''Log all errors, but otherwise let them pass, relying on the caller to + workaround.''' + if exc_info is not None: + log.exception(msg, exc_info=exc_info) + return + + if in_exception_handler(): + log.exception(msg) + return + + log.error(msg) + + def ignore_errors_handler(msg, exc_info=None): '''Ignore all errors, relying on the caller to workaround. Meant for use in the LMS, where an error in one part of the course diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index 047e91e084..cfeac97780 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -3,7 +3,7 @@ from fs.osfs import OSFS from importlib import import_module from lxml import etree from path import path -from xmodule.errorhandlers import strict_error_handler +from xmodule.errorhandlers import logging_error_handler from xmodule.x_module import XModuleDescriptor, XMLParsingSystem from xmodule.mako_module import MakoDescriptorSystem from cStringIO import StringIO @@ -100,7 +100,7 @@ class XMLModuleStore(ModuleStore): """ def __init__(self, data_dir, default_class=None, eager=False, course_dirs=None, - error_handler=strict_error_handler): + error_handler=logging_error_handler): """ Initialize an XMLModuleStore from data_dir