From 31a490b40cee9ac2f94de25af96513a4593c954e Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 10 Jun 2024 16:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E4=BA=86=EF=BC=8C=E4=B8=8D=E5=B0=91?= =?UTF-8?q?=E4=B8=9C=E8=A5=BF=EF=BC=88=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/ica_typing.py | 17 ++++++++--------- ica-rs/src/data_struct/tailchat/status.rs | 3 --- ica-rs/src/py/mod.rs | 20 +++++++++++++++++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ica-rs/ica_typing.py b/ica-rs/ica_typing.py index df5e784..315bf67 100644 --- a/ica-rs/ica_typing.py +++ b/ica-rs/ica_typing.py @@ -1,7 +1,6 @@ # Python 兼容版本 3.8+ -from typing import Callable, Tuple -from typing_extensions import Optional +from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar, Optional """ ica.rs @@ -10,9 +9,9 @@ pub type UserId = i64; pub type MessageId = String; """ class IcaType: - RoomId = int - UserId = int - MessageId = str + RoomId = NewType('RoomId', int) + UserId = NewType('UserId', int) + MessageId = NewType('MessageId', str) """ tailchat.rs @@ -22,10 +21,10 @@ pub type UserId = String; pub type MessageId = String; """ class TailchatType: - GroupId = str - ConverseId = str - UserId = str - MessageId = str + GroupId = NewType('GroupId', str) + ConverseId = NewType('ConverseId', str) + UserId = NewType('UserId', str) + MessageId = NewType('MessageId', str) class IcaStatus: """ diff --git a/ica-rs/src/data_struct/tailchat/status.rs b/ica-rs/src/data_struct/tailchat/status.rs index e33dd23..90bfba5 100644 --- a/ica-rs/src/data_struct/tailchat/status.rs +++ b/ica-rs/src/data_struct/tailchat/status.rs @@ -13,9 +13,6 @@ pub struct LoginData { pub avatar: String, } -/* -{"__v":0,"_id":"66045ddb5163504389a6f5b1","createdAt":"2024-03-27T17:56:43.528Z","members":["6602e20d7b8d10675758e36b","6604482b5163504389a6f481"],"type":"DM","updatedAt":"2024-03-27T17:56:43.528Z"} -*/ #[derive(Debug, Clone, Deserialize, Serialize)] pub struct UpdateDMConverse { /// 会话ID diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 90f1296..7a65b86 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -5,6 +5,7 @@ use std::path::Path; use std::time::SystemTime; use std::{collections::HashMap, path::PathBuf}; +use colored::Colorize; use pyo3::prelude::*; use pyo3::types::PyTuple; use tracing::{debug, info, span, warn, Level}; @@ -19,6 +20,18 @@ pub struct PyStatus { pub type PyPluginData = HashMap; pub type RawPyPlugin = (PathBuf, Option, String); +pub fn get_py_err_traceback(py_err: &PyErr) -> String { + Python::with_gil(|py| match py_err.traceback_bound(py) { + Some(traceback) => match traceback.format() { + Ok(trace) => trace, + Err(e) => format!("{:?}", e), + }, + None => "".to_string(), + }) + .red() + .to_string() +} + #[derive(Debug, Clone)] pub struct PyPlugin { pub file_path: PathBuf, @@ -33,7 +46,12 @@ impl PyPlugin { Ok(raw_file) => match Self::try_from(raw_file) { Ok(plugin) => Some(plugin), Err(e) => { - warn!("加载 Python 插件文件{:?}: {:?} 失败", path, e); + warn!( + "加载 Python 插件文件{:?}: {:?} 失败\n{}", + path, + e, + get_py_err_traceback(&e) + ); None } },