File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 14
14
SNIPPETS_GLOB_PATTERN = "*.py"
15
15
16
16
17
+ class PrintCaptureError (RuntimeError ):
18
+ """Error that happened while capturing print output."""
19
+
20
+ def __init__ (self , e : Exception ) -> None :
21
+ super ().__init__ (
22
+ f"An error occurred when executing code while capturing print outputs: { e } "
23
+ )
24
+
25
+
17
26
def process_print_output (output : str ) -> str :
18
27
"""Format the print output."""
19
28
return f" # Output: { output } " if output else ""
@@ -27,7 +36,7 @@ def execute_and_capture_prints(code: str) -> list[str]:
27
36
try :
28
37
exec (code )
29
38
except Exception as e :
30
- captured_output . write ( f"Error: { e } " )
39
+ raise PrintCaptureError ( e ) from e
31
40
32
41
sys .stdout = sys .__stdout__
33
42
print (f"{ captured_output .getvalue ().strip ().splitlines ()} " )
You can’t perform that action at this time.
0 commit comments