File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 44// git clone https://github.com/marcomq/tauri-plugin-python
55
66#[ cfg( feature = "pyo3" ) ]
7- use pyo3:: PyErr ;
7+ use pyo3:: { prelude :: * , PyErr } ;
88use serde:: { ser:: Serializer , Serialize } ;
99
1010pub type Result < T > = std:: result:: Result < T , Error > ;
@@ -63,9 +63,24 @@ impl From<rustpython_vm::PyRef<rustpython_vm::builtins::PyBaseException>> for Er
6363#[ cfg( feature = "pyo3" ) ]
6464impl From < PyErr > for Error {
6565 fn from ( error : PyErr ) -> Self {
66- let msg = error. to_string ( ) ;
67- println ! ( "error: {}" , & msg) ;
68- Error :: String ( msg)
66+ let error_msg = match pyo3:: Python :: with_gil ( |py| {
67+ let traceback_module = py. import ( "traceback" ) ?;
68+ let traceback_object = error
69+ . traceback ( py)
70+ . ok_or ( pyo3:: exceptions:: PyWarning :: new_err ( "No traceback found." ) )
71+ . inspect ( |r| println ! ( "DEBUG: traceback extracted {:?}" , r) ) ?;
72+ let format_traceback = traceback_module. getattr ( "format_tb" ) ?;
73+ format_traceback
74+ . call1 ( ( traceback_object, ) )
75+ . and_then ( |r| r. extract :: < Vec < String > > ( ) )
76+ } ) {
77+ Ok ( formatted) => formatted. join ( "" ) ,
78+ Err ( _) => {
79+ error. to_string ( ) // Fall back to simple error message
80+ }
81+ } ;
82+
83+ Error :: String ( error_msg)
6984 }
7085}
7186
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ sys.path = sys.path + [{}]
107107 code
108108 ) ;
109109 py_lib:: run_python_internal ( path_import, "main.py" . into ( ) )
110- . unwrap_or_else ( |e| panic ! ( "Error '{e}' initializing main.py" ) ) ;
110+ . unwrap_or_else ( |e| panic ! ( "Error initializing main.py: \n \n {e} \n " ) ) ;
111111}
112112
113113/// Initializes the plugin.
You can’t perform that action at this time.
0 commit comments