Commit cb291871 by Victor Shnayder

Better error checking when content authors mess up answers to numerical response problems.

- give different errors when student or author stuff is messed up (I was seeing "No way to interpret '3' as a number" :P)
- preserve traceback in exception
parent 8cdd5b35
...@@ -756,15 +756,26 @@ class NumericalResponse(LoncapaResponse): ...@@ -756,15 +756,26 @@ class NumericalResponse(LoncapaResponse):
def get_score(self, student_answers): def get_score(self, student_answers):
'''Grade a numeric response ''' '''Grade a numeric response '''
student_answer = student_answers[self.answer_id] student_answer = student_answers[self.answer_id]
try:
correct_ans = complex(self.correct_answer)
except ValueError:
log.debug("Content error--answer '{0}' is not a valid complex number".format(self.correct_answer))
raise StudentInputError("There was a problem with the staff answer to this problem")
try: try:
correct = compare_with_tolerance(evaluator(dict(), dict(), student_answer), correct = compare_with_tolerance(evaluator(dict(), dict(), student_answer),
complex(self.correct_answer), self.tolerance) correct_ans, self.tolerance)
# We should catch this explicitly. # We should catch this explicitly.
# I think this is just pyparsing.ParseException, calc.UndefinedVariable: # I think this is just pyparsing.ParseException, calc.UndefinedVariable:
# But we'd need to confirm # But we'd need to confirm
except: except:
raise StudentInputError("Invalid input: could not interpret '%s' as a number" % # Use the traceback-preserving version of re-raising with a different type
cgi.escape(student_answer)) import sys
type, value, traceback = sys.exc_info()
raise StudentInputError, ("Invalid input: could not interpret '%s' as a number" %
cgi.escape(student_answer)), traceback
if correct: if correct:
return CorrectMap(self.answer_id, 'correct') return CorrectMap(self.answer_id, 'correct')
......
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