summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-11-18 11:26:14 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-11-18 11:26:14 +0100
commit254b3541b84a062ef0bec5b6a8d05e23232f1b1a (patch)
tree4f137c9d838b6549a491dfd3fcb0ae88af780629 /server
parentb7d1b3a3f392e0bd5f4edafb8dd4b9e7d69b305f (diff)
Handle Prolog engine exceptions in PrologSession
Diffstat (limited to 'server')
-rw-r--r--server/prolog_session.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/server/prolog_session.py b/server/prolog_session.py
index cd54e20..c5fa1de 100644
--- a/server/prolog_session.py
+++ b/server/prolog_session.py
@@ -2,6 +2,7 @@
import operator
import threading
+
import prolog.engine
import server
import server.user_session
@@ -101,17 +102,20 @@ class PrologSession(server.LanguageSession):
if pp != (p.group, p.identifier)]
hints = []
- # check if the program is already correct
- passed, _ = problem_module.test(program, solved_problems)
- if passed:
- hints = [{'id': 'program_already_correct'}]
-
- if not hints and hasattr(language_module, 'hint'):
- hints = language_module.hint(program, solved_problems)
- if not hints and hasattr(problem_module, 'hint'):
- hints = problem_module.hint(program, solved_problems)
- if not hints:
- hints = [{'id': 'no_hint'}]
+ try:
+ # check if the program is already correct
+ passed, _ = problem_module.test(program, solved_problems)
+ if passed:
+ hints = [{'id': 'program_already_correct'}]
+
+ if not hints and hasattr(language_module, 'hint'):
+ hints = language_module.hint(program, solved_problems)
+ if not hints and hasattr(problem_module, 'hint'):
+ hints = problem_module.hint(program, solved_problems)
+ if not hints:
+ hints = [{'id': 'no_hint'}]
+ except Exception as ex:
+ hints = [{'id': 'system_error', 'args': {'message': str(ex)}}]
self._instantiate_and_save_hints(language_module, problem_module, hints)
return hints
@@ -130,6 +134,8 @@ class PrologSession(server.LanguageSession):
session.update_solution(problem_id, done=True)
except AttributeError as ex:
hints = [{'id': 'system_error', 'args': {'message': 'test function does not exist'}}]
+ except Exception as ex:
+ hints = [{'id': 'system_error', 'args': {'message': str(ex)}}]
self._instantiate_and_save_hints(language_module, problem_module, hints)
return hints