From 97cdb67b49f0cc5295d8e543ac6d7d76a3ed10f4 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 12 Jul 2012 19:31:13 -0400 Subject: [PATCH] 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) --- common/lib/xmodule/xmodule/raw_module.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/raw_module.py b/common/lib/xmodule/xmodule/raw_module.py index 9fe9a9198b..7cead5990c 100644 --- a/common/lib/xmodule/xmodule/raw_module.py +++ b/common/lib/xmodule/xmodule/raw_module.py @@ -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