diff --git a/edx_arch_experiments/codejail_service/tests/test_views.py b/edx_arch_experiments/codejail_service/tests/test_views.py index 0aa005d..5ca1afc 100644 --- a/edx_arch_experiments/codejail_service/tests/test_views.py +++ b/edx_arch_experiments/codejail_service/tests/test_views.py @@ -105,7 +105,7 @@ def test_unsafely(self): ({}, 'code'), ) def test_missing_params(self, params, missing): - """code and globals_dict are required""" + """Two code and globals_dict params are required.""" self._test_codejail_api( params=params, exp_status=400, exp_body={ @@ -114,6 +114,7 @@ def test_missing_params(self, params, missing): ) def test_extra_files(self): + """Check that we can include a course library.""" # "Course library" containing `course_library.triangular_number`. # # It's tempting to use zipfile to write to an io.BytesIO so @@ -139,3 +140,10 @@ def test_extra_files(self): files={'python_lib.zip': lib_zip}, exp_status=200, exp_body={'globals_dict': {'result': 21}}, ) + + def test_exception(self): + """Report exceptions from jailed code.""" + self._test_codejail_api( + params={'code': '1/0', 'globals_dict': {}}, + exp_status=200, exp_body={'emsg': 'ZeroDivisionError: division by zero'}, + ) diff --git a/edx_arch_experiments/codejail_service/views.py b/edx_arch_experiments/codejail_service/views.py index a67afa4..209300f 100644 --- a/edx_arch_experiments/codejail_service/views.py +++ b/edx_arch_experiments/codejail_service/views.py @@ -164,8 +164,8 @@ def code_exec_view_v0(request): slug=slug, ) except SafeExecException as e: - log.debug("CodejailService execution failed for {slug=} with: {e!r}") - return Response({'emsg': f"Code jail execution failed: {e!r}"}) + log.debug("CodejailService execution failed for {slug=} with: {e}") + return Response({'emsg': str(e)}) log.debug("CodejailService execution succeeded for {slug=}, with globals={output_globals_dict!r}") return Response({'globals_dict': output_globals_dict})