Log error messages when failing to parse xml from a string that contain context of where the error occurred in the string (in definition_to_xml)

This commit is contained in:
Calen Pennington
2012-07-12 19:31:13 -04:00
parent 57d8361acb
commit 97cdb67b49

View File

@@ -2,7 +2,9 @@ from pkg_resources import resource_string
from lxml import etree
from xmodule.mako_module import MakoModuleDescriptor
from xmodule.xml_module import XmlDescriptor
import logging
log = logging.getLogger(__name__)
class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
"""
@@ -24,4 +26,13 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
return {'data': etree.tostring(xml_object)}
def definition_to_xml(self, resource_fs):
return etree.fromstring(self.definition['data'])
try:
return etree.fromstring(self.definition['data'])
except etree.XMLSyntaxError as err:
lines = self.definition['data'].split('\n')
line, offset = err.position
log.exception("Unable to create xml for problem {loc}. Context: '{context}'".format(
context=lines[line-1][offset - 40:offset + 40],
loc=self.location
))
raise