Skip to content

Commit 4d07511

Browse files
committed
🚧 Debug code embedding script
1 parent ab2991d commit 4d07511

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

dev/scripts/format_snippet_prints.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
SNIPPETS_GLOB_PATTERN = "*.py"
1515

1616

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+
1726
def process_print_output(output: str) -> str:
1827
"""Format the print output."""
1928
return f" # Output: {output}" if output else ""
@@ -27,7 +36,7 @@ def execute_and_capture_prints(code: str) -> list[str]:
2736
try:
2837
exec(code)
2938
except Exception as e:
30-
captured_output.write(f"Error: {e}")
39+
raise PrintCaptureError(e) from e
3140

3241
sys.stdout = sys.__stdout__
3342
print(f"{captured_output.getvalue().strip().splitlines()}")

0 commit comments

Comments
 (0)