From 6dedf9885f27110920a293c2ebfe12d158b34ccf Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 16 May 2024 19:30:09 -1000 Subject: [PATCH] fix: code execution error handling --- src/lib/components/chat/Messages/CodeBlock.svelte | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/components/chat/Messages/CodeBlock.svelte b/src/lib/components/chat/Messages/CodeBlock.svelte index 3ed78dd41..d551fa66e 100644 --- a/src/lib/components/chat/Messages/CodeBlock.svelte +++ b/src/lib/components/chat/Messages/CodeBlock.svelte @@ -165,11 +165,16 @@ } }); - result = pyodide.runPython(code); + try { + result = pyodide.runPython(code); - console.log(result); - console.log(stdout); - console.log(stderr); + console.log(result); + console.log(stdout); + console.log(stderr); + } catch (error) { + console.error('Error:', error); + stderr = error; + } }; $: highlightedCode = code ? hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value : '';