diff --git a/pyscriptjs/src/pyodide.ts b/pyscriptjs/src/pyodide.ts index 672b9e5a..759ba312 100644 --- a/pyscriptjs/src/pyodide.ts +++ b/pyscriptjs/src/pyodide.ts @@ -77,7 +77,7 @@ export class PyodideRuntime extends Runtime { logger.info('pyodide loaded and initialized'); } - run(code: string) { + run(code: string): unknown { return this.interpreter.runPython(code); } diff --git a/pyscriptjs/src/runtime.ts b/pyscriptjs/src/runtime.ts index 4bb57c5b..29e2501a 100644 --- a/pyscriptjs/src/runtime.ts +++ b/pyscriptjs/src/runtime.ts @@ -55,7 +55,7 @@ export abstract class Runtime extends Object { * (asynchronously) which can call its own API behind the scenes. * Python exceptions are turned into JS exceptions. * */ - abstract run(code: string); + abstract run(code: string): unknown; /** * Same as run, but Python exceptions are not propagated: instead, they @@ -64,16 +64,14 @@ export abstract class Runtime extends Object { * This is a bad API and should be killed/refactored/changed eventually, * but for now we have code which relies on it. * */ - runButDontRaise(code: string) { - let result - try{ - result = this.run(code) + runButDontRaise(code: string): unknown { + let result: unknown; + try { + result = this.run(code); + } catch (error: unknown) { + logger.error('Error:', error); } - catch (err){ - const error = err as Error - logger.error('Error:', error) - } - return result + return result; } /**