feat(error): add Rust AppError enum and migrate command modules
- AppError enum with 10 variants (Database, Auth, Filesystem, Ipc, NotFound,
Validation, Sidecar, Config, Network, Internal) + serde tag serialization
- From impls for rusqlite::Error, std::io::Error, serde_json::Error
- Migrated 9 command modules from Result<T, String> to Result<T, AppError>
- Frontend receives structured {kind, detail} objects via IPC
This commit is contained in:
parent
365c420901
commit
8b3b0ab720
11 changed files with 319 additions and 81 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use tauri::State;
|
||||
use crate::AppState;
|
||||
use crate::error::AppError;
|
||||
use crate::session::{AgentMessageRecord, ProjectAgentState, SessionMetric, SessionAnchorRecord};
|
||||
|
||||
// --- Agent message persistence ---
|
||||
|
|
@ -11,7 +12,7 @@ pub fn agent_messages_save(
|
|||
project_id: String,
|
||||
sdk_session_id: Option<String>,
|
||||
messages: Vec<AgentMessageRecord>,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.save_agent_messages(
|
||||
&session_id,
|
||||
&project_id,
|
||||
|
|
@ -24,7 +25,7 @@ pub fn agent_messages_save(
|
|||
pub fn agent_messages_load(
|
||||
state: State<'_, AppState>,
|
||||
project_id: String,
|
||||
) -> Result<Vec<AgentMessageRecord>, String> {
|
||||
) -> Result<Vec<AgentMessageRecord>, AppError> {
|
||||
state.session_db.load_agent_messages(&project_id)
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ pub fn agent_messages_load(
|
|||
pub fn project_agent_state_save(
|
||||
state: State<'_, AppState>,
|
||||
agent_state: ProjectAgentState,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.save_project_agent_state(&agent_state)
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ pub fn project_agent_state_save(
|
|||
pub fn project_agent_state_load(
|
||||
state: State<'_, AppState>,
|
||||
project_id: String,
|
||||
) -> Result<Option<ProjectAgentState>, String> {
|
||||
) -> Result<Option<ProjectAgentState>, AppError> {
|
||||
state.session_db.load_project_agent_state(&project_id)
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ pub fn project_agent_state_load(
|
|||
pub fn session_metric_save(
|
||||
state: State<'_, AppState>,
|
||||
metric: SessionMetric,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.save_session_metric(&metric)
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +62,7 @@ pub fn session_metrics_load(
|
|||
state: State<'_, AppState>,
|
||||
project_id: String,
|
||||
limit: i64,
|
||||
) -> Result<Vec<SessionMetric>, String> {
|
||||
) -> Result<Vec<SessionMetric>, AppError> {
|
||||
state.session_db.load_session_metrics(&project_id, limit)
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +72,7 @@ pub fn session_metrics_load(
|
|||
pub fn session_anchors_save(
|
||||
state: State<'_, AppState>,
|
||||
anchors: Vec<SessionAnchorRecord>,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.save_session_anchors(&anchors)
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +80,7 @@ pub fn session_anchors_save(
|
|||
pub fn session_anchors_load(
|
||||
state: State<'_, AppState>,
|
||||
project_id: String,
|
||||
) -> Result<Vec<SessionAnchorRecord>, String> {
|
||||
) -> Result<Vec<SessionAnchorRecord>, AppError> {
|
||||
state.session_db.load_session_anchors(&project_id)
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +88,7 @@ pub fn session_anchors_load(
|
|||
pub fn session_anchor_delete(
|
||||
state: State<'_, AppState>,
|
||||
id: String,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.delete_session_anchor(&id)
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ pub fn session_anchor_delete(
|
|||
pub fn session_anchors_clear(
|
||||
state: State<'_, AppState>,
|
||||
project_id: String,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.delete_project_anchors(&project_id)
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +105,6 @@ pub fn session_anchor_update_type(
|
|||
state: State<'_, AppState>,
|
||||
id: String,
|
||||
anchor_type: String,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<(), AppError> {
|
||||
state.session_db.update_anchor_type(&id, &anchor_type)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue