refac: pyodide worker error handling

This commit is contained in:
Timothy J. Baek 2024-05-19 05:19:48 -07:00
parent 78cbdbc63f
commit 066789d423
2 changed files with 6 additions and 2 deletions

View File

@ -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 = '';

View File

@ -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 });
};