handle python exception
This commit is contained in:
parent
22e826336a
commit
e1f03c4009
2 changed files with 9 additions and 4 deletions
Binary file not shown.
|
@ -32,10 +32,15 @@ const PyodideWrapper = {
|
||||||
stdout: (data: string) => stdOutAndErr.push(data),
|
stdout: (data: string) => stdOutAndErr.push(data),
|
||||||
stderr: (data: string) => stdOutAndErr.push(data),
|
stderr: (data: string) => stdOutAndErr.push(data),
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
const result = await pyodide.runPythonAsync(code);
|
const result = await pyodide.runPythonAsync(code);
|
||||||
if (result) {
|
if (result) {
|
||||||
stdOutAndErr.push(result.toString());
|
stdOutAndErr.push(result.toString());
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
stdOutAndErr.push((e as Error).toString());
|
||||||
|
}
|
||||||
return stdOutAndErr.join('\n');
|
return stdOutAndErr.join('\n');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -64,7 +69,7 @@ export default function CanvasPyInterpreter() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
runCode();
|
runCode();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, [canvasData?.content]);
|
||||||
|
|
||||||
if (canvasData?.type !== CanvasType.PY_INTERPRETER) {
|
if (canvasData?.type !== CanvasType.PY_INTERPRETER) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue