Commit 97cdb67b by Calen Pennington

Log error messages when failing to parse xml from a string that contain context…

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)
parent 57d8361a
...@@ -2,7 +2,9 @@ from pkg_resources import resource_string ...@@ -2,7 +2,9 @@ from pkg_resources import resource_string
from lxml import etree from lxml import etree
from xmodule.mako_module import MakoModuleDescriptor from xmodule.mako_module import MakoModuleDescriptor
from xmodule.xml_module import XmlDescriptor from xmodule.xml_module import XmlDescriptor
import logging
log = logging.getLogger(__name__)
class RawDescriptor(MakoModuleDescriptor, XmlDescriptor): class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
""" """
...@@ -24,4 +26,13 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor): ...@@ -24,4 +26,13 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
return {'data': etree.tostring(xml_object)} return {'data': etree.tostring(xml_object)}
def definition_to_xml(self, resource_fs): def definition_to_xml(self, resource_fs):
try:
return etree.fromstring(self.definition['data']) 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
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