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 4
4
// git clone https://github.com/marcomq/tauri-plugin-python
5
5
6
6
#[ cfg( feature = "pyo3" ) ]
7
- use pyo3:: PyErr ;
7
+ use pyo3:: { prelude :: * , PyErr } ;
8
8
use serde:: { ser:: Serializer , Serialize } ;
9
9
10
10
pub type Result < T > = std:: result:: Result < T , Error > ;
@@ -63,9 +63,24 @@ impl From<rustpython_vm::PyRef<rustpython_vm::builtins::PyBaseException>> for Er
63
63
#[ cfg( feature = "pyo3" ) ]
64
64
impl From < PyErr > for Error {
65
65
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)
69
84
}
70
85
}
71
86
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ sys.path = sys.path + [{}]
107
107
code
108
108
) ;
109
109
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 " ) ) ;
111
111
}
112
112
113
113
/// Initializes the plugin.
You can’t perform that action at this time.
0 commit comments