Skip to content

Commit 3b5b6f7

Browse files
author
RabidSheep55
committed
raise custom EvaluationException
1 parent 952ffd9 commit 3b5b6f7

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

app/evaluation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from evaluation_function_utils.errors import EvaluationException
2+
3+
14
def evaluation_function(response, answer, params) -> dict:
25
"""
36
Function used to grade a student response.
@@ -23,24 +26,29 @@ def evaluation_function(response, answer, params) -> dict:
2326
req_type = params.get("type", False)
2427

2528
if not req_type:
26-
raise SyntaxError("params.type is a required field")
29+
raise EvaluationException(
30+
"The evaluation function couldn't process this request: missing parameter",
31+
missing="params.type")
2732

2833
cast_type = type_dict.get(req_type, False)
2934

3035
if not cast_type:
31-
raise SyntaxError(f"Supplied type {req_type} not available")
36+
raise EvaluationException(f"Supplied type {req_type} not available",
37+
valid_types=list(type_dict.keys()))
3238

3339
# Try cast each of the inputs to their requested type:
3440
errors = []
3541
try:
3642
res = cast_type(response)
3743
except ValueError as e:
38-
raise ValueError(f"Could not cast `response` parameter to {req_type}")
44+
raise EvaluationException(
45+
f"Could not cast `response` parameter to {req_type}")
3946

4047
try:
4148
ans = cast_type(answer)
4249
except ValueError as e:
43-
raise ValueError(f"Could not cast `answer` parameter to {req_type}")
50+
raise EvaluationException(
51+
f"Could not cast `answer` parameter to {req_type}")
4452

4553
# Are they equal?
4654
return {"is_correct": res == ans}

0 commit comments

Comments
 (0)