fix(error): migrate session submodules + btmsg/bttask backends to AppError

- session/*.rs (sessions, layout, settings, ssh, agents, metrics, anchors)
  now return Result<T, AppError> internally, not just at command boundary
- btmsg.rs and bttask.rs backends migrated to AppError::Database
- 116 cargo tests passing
This commit is contained in:
Hibryda 2026-03-18 01:32:07 +01:00
parent eb04e7e5b5
commit f19b69f018
11 changed files with 264 additions and 255 deletions

View file

@ -4,130 +4,130 @@ use crate::groups;
#[tauri::command]
pub fn btmsg_get_agents(group_id: String) -> Result<Vec<btmsg::BtmsgAgent>, AppError> {
btmsg::get_agents(&group_id).map_err(AppError::database)
btmsg::get_agents(&group_id)
}
#[tauri::command]
pub fn btmsg_unread_count(agent_id: String) -> Result<i32, AppError> {
btmsg::unread_count(&agent_id).map_err(AppError::database)
btmsg::unread_count(&agent_id)
}
#[tauri::command]
pub fn btmsg_unread_messages(agent_id: String) -> Result<Vec<btmsg::BtmsgMessage>, AppError> {
btmsg::unread_messages(&agent_id).map_err(AppError::database)
btmsg::unread_messages(&agent_id)
}
#[tauri::command]
pub fn btmsg_history(agent_id: String, other_id: String, limit: i32) -> Result<Vec<btmsg::BtmsgMessage>, AppError> {
btmsg::history(&agent_id, &other_id, limit).map_err(AppError::database)
btmsg::history(&agent_id, &other_id, limit)
}
#[tauri::command]
pub fn btmsg_send(from_agent: String, to_agent: String, content: String) -> Result<String, AppError> {
btmsg::send_message(&from_agent, &to_agent, &content).map_err(AppError::database)
btmsg::send_message(&from_agent, &to_agent, &content)
}
#[tauri::command]
pub fn btmsg_set_status(agent_id: String, status: String) -> Result<(), AppError> {
btmsg::set_status(&agent_id, &status).map_err(AppError::database)
btmsg::set_status(&agent_id, &status)
}
#[tauri::command]
pub fn btmsg_ensure_admin(group_id: String) -> Result<(), AppError> {
btmsg::ensure_admin(&group_id).map_err(AppError::database)
btmsg::ensure_admin(&group_id)
}
#[tauri::command]
pub fn btmsg_all_feed(group_id: String, limit: i32) -> Result<Vec<btmsg::BtmsgFeedMessage>, AppError> {
btmsg::all_feed(&group_id, limit).map_err(AppError::database)
btmsg::all_feed(&group_id, limit)
}
#[tauri::command]
pub fn btmsg_mark_read(reader_id: String, sender_id: String) -> Result<(), AppError> {
btmsg::mark_read_conversation(&reader_id, &sender_id).map_err(AppError::database)
btmsg::mark_read_conversation(&reader_id, &sender_id)
}
#[tauri::command]
pub fn btmsg_get_channels(group_id: String) -> Result<Vec<btmsg::BtmsgChannel>, AppError> {
btmsg::get_channels(&group_id).map_err(AppError::database)
btmsg::get_channels(&group_id)
}
#[tauri::command]
pub fn btmsg_channel_messages(channel_id: String, limit: i32) -> Result<Vec<btmsg::BtmsgChannelMessage>, AppError> {
btmsg::get_channel_messages(&channel_id, limit).map_err(AppError::database)
btmsg::get_channel_messages(&channel_id, limit)
}
#[tauri::command]
pub fn btmsg_channel_send(channel_id: String, from_agent: String, content: String) -> Result<String, AppError> {
btmsg::send_channel_message(&channel_id, &from_agent, &content).map_err(AppError::database)
btmsg::send_channel_message(&channel_id, &from_agent, &content)
}
#[tauri::command]
pub fn btmsg_create_channel(name: String, group_id: String, created_by: String) -> Result<String, AppError> {
btmsg::create_channel(&name, &group_id, &created_by).map_err(AppError::database)
btmsg::create_channel(&name, &group_id, &created_by)
}
#[tauri::command]
pub fn btmsg_add_channel_member(channel_id: String, agent_id: String) -> Result<(), AppError> {
btmsg::add_channel_member(&channel_id, &agent_id).map_err(AppError::database)
btmsg::add_channel_member(&channel_id, &agent_id)
}
/// Register all agents from a GroupsFile into the btmsg database.
/// Creates/updates agent records, sets up contact permissions, ensures review channels.
#[tauri::command]
pub fn btmsg_register_agents(config: groups::GroupsFile) -> Result<(), AppError> {
btmsg::register_agents_from_groups(&config).map_err(AppError::database)
btmsg::register_agents_from_groups(&config)
}
// ---- Per-message acknowledgment (seen_messages) ----
#[tauri::command]
pub fn btmsg_unseen_messages(agent_id: String, session_id: String) -> Result<Vec<btmsg::BtmsgMessage>, AppError> {
btmsg::unseen_messages(&agent_id, &session_id).map_err(AppError::database)
btmsg::unseen_messages(&agent_id, &session_id)
}
#[tauri::command]
pub fn btmsg_mark_seen(session_id: String, message_ids: Vec<String>) -> Result<(), AppError> {
btmsg::mark_messages_seen(&session_id, &message_ids).map_err(AppError::database)
btmsg::mark_messages_seen(&session_id, &message_ids)
}
#[tauri::command]
pub fn btmsg_prune_seen() -> Result<u64, AppError> {
btmsg::prune_seen_messages(7 * 24 * 3600, 200_000).map_err(AppError::database)
btmsg::prune_seen_messages(7 * 24 * 3600, 200_000)
}
// ---- Heartbeat monitoring ----
#[tauri::command]
pub fn btmsg_record_heartbeat(agent_id: String) -> Result<(), AppError> {
btmsg::record_heartbeat(&agent_id).map_err(AppError::database)
btmsg::record_heartbeat(&agent_id)
}
#[tauri::command]
pub fn btmsg_get_stale_agents(group_id: String, threshold_secs: i64) -> Result<Vec<String>, AppError> {
btmsg::get_stale_agents(&group_id, threshold_secs).map_err(AppError::database)
btmsg::get_stale_agents(&group_id, threshold_secs)
}
#[tauri::command]
pub fn btmsg_get_agent_heartbeats(group_id: String) -> Result<Vec<btmsg::AgentHeartbeat>, AppError> {
btmsg::get_agent_heartbeats(&group_id).map_err(AppError::database)
btmsg::get_agent_heartbeats(&group_id)
}
// ---- Dead letter queue ----
#[tauri::command]
pub fn btmsg_get_dead_letters(group_id: String, limit: i32) -> Result<Vec<btmsg::DeadLetter>, AppError> {
btmsg::get_dead_letters(&group_id, limit).map_err(AppError::database)
btmsg::get_dead_letters(&group_id, limit)
}
#[tauri::command]
pub fn btmsg_clear_dead_letters(group_id: String) -> Result<(), AppError> {
btmsg::clear_dead_letters(&group_id).map_err(AppError::database)
btmsg::clear_dead_letters(&group_id)
}
#[tauri::command]
pub fn btmsg_clear_all_comms(group_id: String) -> Result<(), AppError> {
btmsg::clear_all_communications(&group_id).map_err(AppError::database)
btmsg::clear_all_communications(&group_id)
}
#[tauri::command]
@ -138,22 +138,22 @@ pub fn btmsg_queue_dead_letter(
error: String,
) -> Result<(), AppError> {
btmsg::queue_dead_letter(&from_agent, &to_agent, &content, &error)
.map_err(AppError::database)
}
// ---- Audit log ----
#[tauri::command]
pub fn audit_log_event(agent_id: String, event_type: String, detail: String) -> Result<(), AppError> {
btmsg::log_audit_event(&agent_id, &event_type, &detail).map_err(AppError::database)
btmsg::log_audit_event(&agent_id, &event_type, &detail)
}
#[tauri::command]
pub fn audit_log_list(group_id: String, limit: i32, offset: i32) -> Result<Vec<btmsg::AuditEntry>, AppError> {
btmsg::get_audit_log(&group_id, limit, offset).map_err(AppError::database)
btmsg::get_audit_log(&group_id, limit, offset)
}
#[tauri::command]
pub fn audit_log_for_agent(agent_id: String, limit: i32) -> Result<Vec<btmsg::AuditEntry>, AppError> {
btmsg::get_audit_log_for_agent(&agent_id, limit).map_err(AppError::database)
btmsg::get_audit_log_for_agent(&agent_id, limit)
}

View file

@ -3,22 +3,22 @@ use crate::error::AppError;
#[tauri::command]
pub fn bttask_list(group_id: String) -> Result<Vec<bttask::Task>, AppError> {
bttask::list_tasks(&group_id).map_err(AppError::database)
bttask::list_tasks(&group_id)
}
#[tauri::command]
pub fn bttask_comments(task_id: String) -> Result<Vec<bttask::TaskComment>, AppError> {
bttask::task_comments(&task_id).map_err(AppError::database)
bttask::task_comments(&task_id)
}
#[tauri::command]
pub fn bttask_update_status(task_id: String, status: String, version: i64) -> Result<i64, AppError> {
bttask::update_task_status(&task_id, &status, version).map_err(AppError::database)
bttask::update_task_status(&task_id, &status, version)
}
#[tauri::command]
pub fn bttask_add_comment(task_id: String, agent_id: String, content: String) -> Result<String, AppError> {
bttask::add_comment(&task_id, &agent_id, &content).map_err(AppError::database)
bttask::add_comment(&task_id, &agent_id, &content)
}
#[tauri::command]
@ -31,15 +31,15 @@ pub fn bttask_create(
assigned_to: Option<String>,
) -> Result<String, AppError> {
bttask::create_task(&title, &description, &priority, &group_id, &created_by, assigned_to.as_deref())
.map_err(AppError::database)
}
#[tauri::command]
pub fn bttask_delete(task_id: String) -> Result<(), AppError> {
bttask::delete_task(&task_id).map_err(AppError::database)
bttask::delete_task(&task_id)
}
#[tauri::command]
pub fn bttask_review_queue_count(group_id: String) -> Result<i64, AppError> {
bttask::review_queue_count(&group_id).map_err(AppError::database)
bttask::review_queue_count(&group_id)
}