Spaces:
Sleeping
Sleeping
Improved exception error logging
Browse files
restrictedpython_code_eval.py
CHANGED
@@ -349,15 +349,22 @@ def _check_correctness(check_program, timeout, task_id, completion_id,
|
|
349 |
|
350 |
|
351 |
if not result:
|
352 |
-
result.append("Result evaluates to False (
|
353 |
|
354 |
-
|
355 |
task_id=task_id,
|
356 |
passed=result[0] == "passed",
|
357 |
result=result[0],
|
358 |
completion_id=completion_id,
|
359 |
)
|
360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
|
362 |
class AllowListImporter:
|
363 |
def __init__(self, allowed_imports: List[str]):
|
@@ -500,6 +507,7 @@ def _unsafe_execute(check_program, result, timeout,
|
|
500 |
with time_limit(timeout):
|
501 |
byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)
|
502 |
exec(byte_code, exec_globals, additional_locals)
|
|
|
503 |
result.append("passed")
|
504 |
except EOFError:
|
505 |
result.append("EOF error")
|
@@ -507,6 +515,7 @@ def _unsafe_execute(check_program, result, timeout,
|
|
507 |
result.append("timed out")
|
508 |
except BaseException as e:
|
509 |
result.append(f"failed ({type(e)}): {str(e)}")
|
|
|
510 |
|
511 |
# Needed for cleaning up.
|
512 |
shutil.rmtree = rmtree
|
|
|
349 |
|
350 |
|
351 |
if not result:
|
352 |
+
result.append("Result evaluates to False (probably timed out)")
|
353 |
|
354 |
+
out_dict = dict(
|
355 |
task_id=task_id,
|
356 |
passed=result[0] == "passed",
|
357 |
result=result[0],
|
358 |
completion_id=completion_id,
|
359 |
)
|
360 |
|
361 |
+
if 'failed' in result[0] and len(result) > 1:
|
362 |
+
exc = result[1]
|
363 |
+
out_dict["exception_type"] = type(exc).__name__
|
364 |
+
out_dict["exception_description"] = str(exc)
|
365 |
+
|
366 |
+
return out_dict
|
367 |
+
|
368 |
|
369 |
class AllowListImporter:
|
370 |
def __init__(self, allowed_imports: List[str]):
|
|
|
507 |
with time_limit(timeout):
|
508 |
byte_code = compile_restricted(check_program, filename="<model output>", mode="exec", policy=policy_class)
|
509 |
exec(byte_code, exec_globals, additional_locals)
|
510 |
+
|
511 |
result.append("passed")
|
512 |
except EOFError:
|
513 |
result.append("EOF error")
|
|
|
515 |
result.append("timed out")
|
516 |
except BaseException as e:
|
517 |
result.append(f"failed ({type(e)}): {str(e)}")
|
518 |
+
result.append(e)
|
519 |
|
520 |
# Needed for cleaning up.
|
521 |
shutil.rmtree = rmtree
|