From 066789d423dc1f06aac249fbcec4a732c690b6d0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 19 May 2024 05:19:48 -0700 Subject: [PATCH] refac: pyodide worker error handling --- src/lib/components/chat/Messages/CodeBlock.svelte | 2 +- src/lib/workers/pyodide.worker.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Messages/CodeBlock.svelte b/src/lib/components/chat/Messages/CodeBlock.svelte index ed817c22b..93c9047e1 100644 --- a/src/lib/components/chat/Messages/CodeBlock.svelte +++ b/src/lib/components/chat/Messages/CodeBlock.svelte @@ -5,7 +5,7 @@ import 'highlight.js/styles/github-dark.min.css'; import { loadPyodide } from 'pyodide'; import { tick } from 'svelte'; - import PyodideWorker from '../../../workers/pyodide.worker?worker'; + import PyodideWorker from '$lib/workers/pyodide.worker?worker'; export let id = ''; diff --git a/src/lib/workers/pyodide.worker.ts b/src/lib/workers/pyodide.worker.ts index e463ba8ba..ec2d12004 100644 --- a/src/lib/workers/pyodide.worker.ts +++ b/src/lib/workers/pyodide.worker.ts @@ -59,7 +59,11 @@ self.onmessage = async (event) => { // make sure loading is done await loadPyodideAndPackages(self.packages); - self.result = await self.pyodide.runPythonAsync(code); + try { + self.result = await self.pyodide.runPythonAsync(code); + } catch (error) { + self.stderr = error.toString(); + } self.postMessage({ id, result: self.result, stdout: self.stdout, stderr: self.stderr }); };