From 254b3541b84a062ef0bec5b6a8d05e23232f1b1a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 18 Nov 2015 11:26:14 +0100 Subject: Handle Prolog engine exceptions in PrologSession --- server/prolog_session.py | 28 +++++++++++++++++----------- 1 file 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 -- cgit v1.2.1