Catch syntax errors with .py/.py2

This commit is contained in:
jesopo 2018-10-24 13:40:56 +01:00
parent ae0825650e
commit 99f896ebdd

View file

@ -4,7 +4,15 @@ from src import ModuleManager, utils
EVAL_TEMPLATE = """
import io, json, sys
compiled = compile(sys.stdin.read(), "code", "single")
def fail(s):
old_stdout.write(json.dumps({"success": False, "out": str(e)}))
sys.exit()
try:
compiled = compile(sys.stdin.read(), "code", "single")
except Exception as e:
self.fail(str(e))
old_stdout = sys.stdout
stdout = io.StringIO()
@ -13,8 +21,7 @@ sys.stdout = stdout
try:
result = eval(compiled)
except Exception as e:
old_stdout.write(json.dumps({"success": False, "out": str(e)}))
sys.exit()
self.fail(str(e))
stdout.write("\\n")
if not result == None: