handle python exception

This commit is contained in:
Xuan Son Nguyen 2025-02-08 15:20:24 +01:00
parent 22e826336a
commit e1f03c4009
2 changed files with 9 additions and 4 deletions

Binary file not shown.

View file

@ -32,9 +32,14 @@ const PyodideWrapper = {
stdout: (data: string) => stdOutAndErr.push(data),
stderr: (data: string) => stdOutAndErr.push(data),
});
const result = await pyodide.runPythonAsync(code);
if (result) {
stdOutAndErr.push(result.toString());
try {
const result = await pyodide.runPythonAsync(code);
if (result) {
stdOutAndErr.push(result.toString());
}
} catch (e) {
console.error(e);
stdOutAndErr.push((e as Error).toString());
}
return stdOutAndErr.join('\n');
},
@ -64,7 +69,7 @@ export default function CanvasPyInterpreter() {
useEffect(() => {
runCode();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [canvasData?.content]);
if (canvasData?.type !== CanvasType.PY_INTERPRETER) {
return null;