From d8e40bfb4d23168ced64d45f71c1967057b60cd6 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 29 Jun 2024 01:25:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E7=82=B9error=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/py/call.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index cd2fad6..1f8ff60 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -100,13 +100,29 @@ macro_rules! call_py_func { tokio::spawn(async move { Python::with_gil(|py| { if let Ok(py_func) = get_func($plugin.py_module.bind(py), $func_name) { - if let Err(e) = py_func.call1($args) { + if let Err(py_err) = py_func.call1($args) { let e = PyPluginError::FuncCallError( - e, + py_err, $func_name.to_string(), $plugin_path.to_string_lossy().to_string(), ); - event!(Level::WARN, "failed to call function<{}>: {:?}", $func_name, e); + event!( + Level::WARN, + "failed to call function<{}>: {}\ntraceback: {}", + $func_name, + e, + // 获取 traceback + match &e { + PyPluginError::FuncCallError(py_err, _, _) => match py_err.traceback_bound(py) { + Some(traceback) => match traceback.format() { + Ok(trace) => trace, + Err(trace_e) => format!("failed to format traceback: {:?}", trace_e), + }, + None => "no traceback".to_string(), + }, + _ => unreachable!(), + } + ); } } })