From 4efcfca34a91a350da93c1a9e3d04afc363858d7 Mon Sep 17 00:00:00 2001 From: Ahtisham Shahid Date: Wed, 4 Mar 2020 20:00:58 +0500 Subject: [PATCH] created logs to capture capa problem errors Update logs updated logger --- common/lib/capa/capa/capa_problem.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 006cd67ac4..39f311bf87 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -560,15 +560,22 @@ class LoncapaProblem(object): Returns: a string with the question text """ + + def log_error(): + """ + Temporary method for logging + """ + log.error( + 'KeyError: answer_id: {}, Problem data: {}, problem: {}' + .format(answer_id, self.problem_data, etree.tostring(self.tree)) + ) + _ = get_gettext(self.capa_system.i18n) # Some questions define a prompt with this format: >>This is a prompt<< try: prompt = self.problem_data[answer_id].get('label') except KeyError: - log.error( - 'KeyError: answer_id: %s, Problem data: %s, problem: %s', - (answer_id, self.problem_data, etree.tostring(self.tree)) - ) + log_error() raise if prompt: @@ -585,7 +592,11 @@ class LoncapaProblem(object): # # Starting from answer (the optioninput in this example) we go up and backwards xml_elems = self.tree.xpath('//*[@id="' + answer_id + '"]') + + if len(xml_elems) != 1: + log_error() assert len(xml_elems) == 1 + xml_elem = xml_elems[0].getparent() # Get the element that probably contains the question text