From 7814805c1a88ccd3081b1006c4e6b0db01167a03 Mon Sep 17 00:00:00 2001 From: ichuang Date: Sat, 23 Jun 2012 16:23:27 -0400 Subject: [PATCH] improve capa error handling a bit - for better user experience - if no answer given, then symbolicresponse + customrepsonse now give an error message, instead of doing nothing - in capa_module if lcp.grade_answers fails, in DEBUG mode display alert with useful error message --- common/lib/capa/capa_problem.py | 3 ++- common/lib/capa/responsetypes.py | 2 +- common/lib/xmodule/capa_module.py | 17 ++++++++++------- common/lib/xmodule/seq_module.py | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/common/lib/capa/capa_problem.py b/common/lib/capa/capa_problem.py index e0e1eb160f..67172d4657 100644 --- a/common/lib/capa/capa_problem.py +++ b/common/lib/capa/capa_problem.py @@ -304,7 +304,8 @@ class LoncapaProblem(object): try: exec code in context, context # use "context" for global context; thus defs in code are global within code except Exception: - log.exception("Error while execing code: " + code) + log.exception("Error while execing script code: " + code) + raise responsetypes.LoncapaProblemError("Error while executing script code") return context def _extract_html(self, problemtree): # private diff --git a/common/lib/capa/responsetypes.py b/common/lib/capa/responsetypes.py index ed6ef8f7c4..dc77bdbf8b 100644 --- a/common/lib/capa/responsetypes.py +++ b/common/lib/capa/responsetypes.py @@ -567,7 +567,7 @@ def sympy_check2(): # if there is only one box, and it's empty, then don't evaluate if len(idset)==1 and not submission[0]: - return {idset[0]:'no_answer_entered'} + return CorrectMap(idset[0],'incorrect',msg='No answer entered!') correct = ['unknown'] * len(idset) messages = [''] * len(idset) diff --git a/common/lib/xmodule/capa_module.py b/common/lib/xmodule/capa_module.py index 3566f9b5e3..ad20364a06 100644 --- a/common/lib/xmodule/capa_module.py +++ b/common/lib/xmodule/capa_module.py @@ -409,18 +409,21 @@ class Module(XModule): correct_map = self.lcp.grade_answers(answers) except StudentInputError as inst: # TODO (vshnayder): why is this line here? - self.lcp = LoncapaProblem(self.filestore.open(self.filename), - id=lcp_id, state=old_state, system=self.system) + #self.lcp = LoncapaProblem(self.filestore.open(self.filename), + # id=lcp_id, state=old_state, system=self.system) traceback.print_exc() return {'success': inst.message} - except: + except Exception, err: # TODO: why is this line here? - self.lcp = LoncapaProblem(self.filestore.open(self.filename), - id=lcp_id, state=old_state, system=self.system) + #self.lcp = LoncapaProblem(self.filestore.open(self.filename), + # id=lcp_id, state=old_state, system=self.system) + if self.DEBUG: + msg = "Error checking problem: " + str(err) + msg += '\nTraceback:\n' + traceback.format_exc() + return {'success':msg} + traceback.print_exc() raise Exception,"error in capa_module" - # TODO: Dead code... is this a bug, or just old? - return {'success':'Unknown Error'} self.attempts = self.attempts + 1 self.lcp.done = True diff --git a/common/lib/xmodule/seq_module.py b/common/lib/xmodule/seq_module.py index 8c3a148a51..d3877c3c41 100644 --- a/common/lib/xmodule/seq_module.py +++ b/common/lib/xmodule/seq_module.py @@ -77,6 +77,7 @@ class Module(XModule): contents['progress_status'] = Progress.to_js_status_str(progress) contents['progress_detail'] = Progress.to_js_detail_str(progress) + content = None for (content, element_class) in zip(self.contents, child_classes): new_class = 'other' for c in class_priority: