From 2cb3af1e3531693a3c254cb8375979735ea3b573 Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Wed, 1 May 2013 10:53:22 -0400 Subject: [PATCH] Only throw factorial-related exception on factorial raised exception --- common/lib/capa/capa/responsetypes.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 49f6ee1bee..b06a62ffc6 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1852,12 +1852,18 @@ class FormulaResponse(LoncapaResponse): raise StudentInputError( "Invalid input: " + uv.message + " not permitted in answer") except ValueError as ve: - # This is thrown when fact() or factorial() is used in a formularesponse answer - # that tests on negative and/or non-integer inputs - log.debug( - '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 'factorial' in ve.message: + # This is thrown when fact() or factorial() is used in a formularesponse answer + # that tests on negative and/or non-integer inputs + # ve.message will be: `factorial() only accepts integral values` or `factorial() not defined for negative values` + log.debug( + '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: # traceback.print_exc() log.debug('formularesponse: error %s in formula' % err)