Commit 2cb3af1e by Sarina Canelake

Only throw factorial-related exception on factorial raised exception

parent 95a224fc
...@@ -1852,12 +1852,18 @@ class FormulaResponse(LoncapaResponse): ...@@ -1852,12 +1852,18 @@ class FormulaResponse(LoncapaResponse):
raise StudentInputError( raise StudentInputError(
"Invalid input: " + uv.message + " not permitted in answer") "Invalid input: " + uv.message + " not permitted in answer")
except ValueError as ve: except ValueError as ve:
# This is thrown when fact() or factorial() is used in a formularesponse answer if 'factorial' in ve.message:
# that tests on negative and/or non-integer inputs # This is thrown when fact() or factorial() is used in a formularesponse answer
log.debug( # that tests on negative and/or non-integer inputs
'formularesponse: factorial function used in response that tests negative and/or non-integer inputs. given={0}'.format(given)) # ve.message will be: `factorial() only accepts integral values` or `factorial() not defined for negative values`
raise StudentInputError( log.debug(
"factorial function not permitted in answer for this problem. Provided answer was: {0}".format(given)) 'formularesponse: factorial function used in response that tests negative and/or non-integer inputs. given={0}'.format(given))
raise StudentInputError(
"factorial function not permitted in answer for this problem. Provided answer was: {0}".format(given))
# If non-factorial related ValueError thrown, handle it the same as any other Exception
log.debug('formularesponse: error {0} in formula'.format(ve))
raise StudentInputError("Invalid input: Could not parse '%s' as a formula" %
cgi.escape(given))
except Exception as err: except Exception as err:
# traceback.print_exc() # traceback.print_exc()
log.debug('formularesponse: error %s in formula' % err) log.debug('formularesponse: error %s in formula' % err)
......
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