Commit a8afe5ed by Victor Shnayder

Change modulestore to use a logging error handler

* log errors, but don't fail
parent 9c92aef6
import logging
import sys 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): def strict_error_handler(msg, exc_info=None):
''' '''
Do not let errors pass. If exc_info is not None, ignore msg, and just 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): ...@@ -11,13 +18,26 @@ def strict_error_handler(msg, exc_info=None):
if exc_info is not None: if exc_info is not None:
raise exc_info[0], exc_info[1], exc_info[2] raise exc_info[0], exc_info[1], exc_info[2]
# Check if there is an exception being handled somewhere up the stack if in_exception_handler():
if sys.exc_info() != (None, None, None):
raise raise
raise Exception(msg) 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): def ignore_errors_handler(msg, exc_info=None):
'''Ignore all errors, relying on the caller to workaround. '''Ignore all errors, relying on the caller to workaround.
Meant for use in the LMS, where an error in one part of the course Meant for use in the LMS, where an error in one part of the course
......
...@@ -3,7 +3,7 @@ from fs.osfs import OSFS ...@@ -3,7 +3,7 @@ from fs.osfs import OSFS
from importlib import import_module from importlib import import_module
from lxml import etree from lxml import etree
from path import path 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.x_module import XModuleDescriptor, XMLParsingSystem
from xmodule.mako_module import MakoDescriptorSystem from xmodule.mako_module import MakoDescriptorSystem
from cStringIO import StringIO from cStringIO import StringIO
...@@ -100,7 +100,7 @@ class XMLModuleStore(ModuleStore): ...@@ -100,7 +100,7 @@ class XMLModuleStore(ModuleStore):
""" """
def __init__(self, data_dir, default_class=None, eager=False, def __init__(self, data_dir, default_class=None, eager=False,
course_dirs=None, course_dirs=None,
error_handler=strict_error_handler): error_handler=logging_error_handler):
""" """
Initialize an XMLModuleStore from data_dir Initialize an XMLModuleStore from data_dir
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment