fix: rowid column shift in get_message_with_rowid; add file logging and frontend error reporting

This commit is contained in:
Xianren Studio
2026-08-13 23:31:06 +08:00
parent 57df39e4ce
commit 00624d81cf
8 changed files with 77 additions and 4 deletions
+2
View File
@@ -21,12 +21,14 @@ tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
tracing-subscriber.workspace = true
tracing.workspace = true
tracing-appender.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
reqwest.workspace = true
futures.workspace = true
uuid.workspace = true
dirs.workspace = true
xianren-core = { path = "../../crates/core" }
xianren-engine = { path = "../../crates/engine" }
xianren-download = { path = "../../crates/download" }
+9
View File
@@ -19,6 +19,7 @@ pub struct AppInfo {
pub version: String,
pub platform: String,
pub models_dir: String,
pub logs_dir: String,
pub engine_bin: Option<String>,
pub engine_exists: bool,
pub db_path: String,
@@ -133,6 +134,7 @@ pub fn app_info(state: State<'_, App>) -> AppInfo {
version: env!("CARGO_PKG_VERSION").to_string(),
platform: std::env::consts::OS.to_string(),
models_dir: state.core.models_dir.to_string_lossy().to_string(),
logs_dir: state.core.logs_dir.to_string_lossy().to_string(),
engine_exists: engine_bin
.as_ref()
.is_some_and(|p| PathBuf::from(p).exists()),
@@ -1416,3 +1418,10 @@ pub async fn server_status(state: State<'_, App>) -> Result<serde_json::Value, S
pub fn open_path(path: String) -> Result<(), String> {
tauri_plugin_opener::open_path(path, None::<&str>).map_err(|e| e.to_string())
}
/// 前端上报运行时错误:写入本地日志便于排查。
#[tauri::command]
pub fn report_error(source: String, message: String) -> Result<(), String> {
tracing::error!(source = %source, error = %message, "frontend reported error");
Ok(())
}
+10
View File
@@ -17,11 +17,20 @@ pub struct App {
}
pub fn run() {
let data_dir = dirs::data_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join("XianrenStudio");
let logs_dir = data_dir.join("logs");
let _ = std::fs::create_dir_all(&logs_dir);
let file_appender = tracing_appender::rolling::daily(&logs_dir, "app.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "info".into()),
)
.with_writer(non_blocking)
.with_ansi(false)
.init();
tauri::Builder::default()
@@ -115,6 +124,7 @@ pub fn run() {
commands::edit_message,
commands::list_message_versions,
commands::apply_message_version,
commands::report_error,
commands::download_enqueue,
commands::server_start,
commands::server_stop,