From 1140036f20a6ff74107c0cebefc6e130322858c5 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 16 May 2024 17:55:07 -1000 Subject: [PATCH] feat: python error handling --- src/lib/components/chat/Messages/CodeBlock.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Messages/CodeBlock.svelte b/src/lib/components/chat/Messages/CodeBlock.svelte index 39e3a9fd3..fc7381442 100644 --- a/src/lib/components/chat/Messages/CodeBlock.svelte +++ b/src/lib/components/chat/Messages/CodeBlock.svelte @@ -47,7 +47,11 @@ original_stdout = sys.stdout # Replace the standard output with the StringIO object sys.stdout = output_capture -${text} +try: + ${text} +except Exception as e: + # Capture any errors and write them to the output capture + print(f"Error: {e}", file=output_capture) # Restore the original standard output sys.stdout = original_stdout