From d3371e5417052319c81ebba1287bbb53dfe50913 Mon Sep 17 00:00:00 2001 From: James Wang Date: Sun, 17 Apr 2016 08:58:32 -0400 Subject: [PATCH] Check for syntax errors in new graders --- server/api/problem.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/api/problem.py b/server/api/problem.py index 8f639e2..d1d0f6b 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -32,6 +32,11 @@ def problem_add(): if title_exist: raise WebException("Problem name already taken.") + try: + exec(grader_contents) + except Exception, e: + raise WebException("There is a syntax error in the grader: %s" % e) + problem = Problems(pid, title, category, description, value, hint=hint) db.session.add(problem) db.session.commit() @@ -87,6 +92,10 @@ def problem_update(): hint = request.form["hint"] value = request.form["value"] grader_contents = request.form["grader_contents"] + try: + exec(grader_contents) + except Exception, e: + raise WebException("There is a syntax error in the grader: %s" % e) problem = Problems.query.filter_by(pid=pid).first() if problem: