From aff1622fa2ac4a3090f64c23a6cb12ce1790dc9a Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Tue, 5 Nov 2024 14:59:37 +0000 Subject: [PATCH] Improve errors from pyodide by using filename --- gui/src/app/Scripting/Analysis/AnalysisPyWindow.tsx | 1 + gui/src/app/Scripting/DataGeneration/DataPyWindow.tsx | 1 + gui/src/app/Scripting/pyodide/pyodideWorker.ts | 5 ++++- gui/src/app/Scripting/pyodide/pyodideWorkerTypes.ts | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gui/src/app/Scripting/Analysis/AnalysisPyWindow.tsx b/gui/src/app/Scripting/Analysis/AnalysisPyWindow.tsx index 7ce845a..f33db03 100644 --- a/gui/src/app/Scripting/Analysis/AnalysisPyWindow.tsx +++ b/gui/src/app/Scripting/Analysis/AnalysisPyWindow.tsx @@ -59,6 +59,7 @@ const AnalysisPyWindow: FunctionComponent = ({ loadsDraws: true, showsPlots: true, producesData: false, + filenameForErrors: FileNames.ANALYSISPYFILE, }, files, }); diff --git a/gui/src/app/Scripting/DataGeneration/DataPyWindow.tsx b/gui/src/app/Scripting/DataGeneration/DataPyWindow.tsx index 988c88a..3b5554e 100644 --- a/gui/src/app/Scripting/DataGeneration/DataPyWindow.tsx +++ b/gui/src/app/Scripting/DataGeneration/DataPyWindow.tsx @@ -45,6 +45,7 @@ const DataPyWindow: FunctionComponent = () => { loadsDraws: false, showsPlots: false, producesData: true, + filenameForErrors: FileNames.DATAPYFILE, }, }); }, diff --git a/gui/src/app/Scripting/pyodide/pyodideWorker.ts b/gui/src/app/Scripting/pyodide/pyodideWorker.ts index 4c0737f..bc76fc2 100644 --- a/gui/src/app/Scripting/pyodide/pyodideWorker.ts +++ b/gui/src/app/Scripting/pyodide/pyodideWorker.ts @@ -122,7 +122,10 @@ const run = async ( } setStatus("running"); - pyodide.runPython(script, { globals }); + await pyodide.runPythonAsync(script, { + globals, + filename: spPySettings.filenameForErrors, + }); succeeded = true; } catch (e: any) { console.error(e); diff --git a/gui/src/app/Scripting/pyodide/pyodideWorkerTypes.ts b/gui/src/app/Scripting/pyodide/pyodideWorkerTypes.ts index 9830344..abe63aa 100644 --- a/gui/src/app/Scripting/pyodide/pyodideWorkerTypes.ts +++ b/gui/src/app/Scripting/pyodide/pyodideWorkerTypes.ts @@ -8,6 +8,7 @@ export type PyodideRunSettings = Partial<{ loadsDraws: boolean; showsPlots: boolean; producesData: boolean; + filenameForErrors: string; }>; export type MessageToPyodideWorker = {