From fa83bdae5afce49a09a165c7155367a061471c92 Mon Sep 17 00:00:00 2001 From: Saagar Patel Date: Wed, 22 Apr 2026 16:09:57 +0200 Subject: [PATCH] refactor(src): migrate last two String-typed Tauri commands to AppError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final cleanup for ADR 0012. Post-session audit caught two #[tauri::command] functions that slipped through every prior migration PR: - get_allow_unverified_local_models (Result) - set_allow_unverified_local_models (Result<(), String>) Both live in commands/mod.rs and are registered via registry.rs:66 and :76 respectively. They escaped the earlier domain-by-domain passes because they don't fit any domain — they're the unverified- model settings flag. Changes: - get_allow_unverified_local_models: bridges the still-String internal helper allow_unverified_local_models via .map_err(AppError::internal). The helper stays on String because it's also consumed by an unregistered dead-code wrapper (load_custom_model in mod.rs, shadow of model_commands::load_custom_model) that would cascade otherwise. - set_allow_unverified_local_models: full migration with db_lock_failed / db_not_initialized / db_query_failed. Verified every #[tauri::command] across the commands/ tree with: awk '/^#\[tauri::command\]/ { flag=1 } flag && /^pub (async )?fn/ { ... check Result<_, String> ... flag=0 }' and confirmed zero String-returning Tauri commands remain. Verified: - cargo check --all-targets clean - cargo test --lib: 311 pass, 1 ignored - cargo test --test command_contracts: 8 pass --- src-tauri/src/commands/mod.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index 77e0667..7e1157a 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -149,22 +149,32 @@ fn custom_model_verification_status( } #[tauri::command] -pub fn get_allow_unverified_local_models(state: State<'_, AppState>) -> Result { - allow_unverified_local_models(state.inner()) +pub fn get_allow_unverified_local_models( + state: State<'_, AppState>, +) -> Result { + // allow_unverified_local_models is kept on String because it's shared with + // still-unmigrated dead-code wrappers further down in this file. Bridge via + // AppError::internal to preserve the [CODE] message wire format. + allow_unverified_local_models(state.inner()).map_err(crate::error::AppError::internal) } #[tauri::command] pub fn set_allow_unverified_local_models( state: State<'_, AppState>, enabled: bool, -) -> Result<(), String> { - let db_lock = state.db.lock().map_err(|e| e.to_string())?; - let db = db_lock.as_ref().ok_or("Database not initialized")?; +) -> Result<(), crate::error::AppError> { + let db_lock = state + .db + .lock() + .map_err(|_| crate::error::AppError::db_lock_failed())?; + let db = db_lock + .as_ref() + .ok_or_else(crate::error::AppError::db_not_initialized)?; db.set_setting_value( ALLOW_UNVERIFIED_LOCAL_MODELS_KEY, if enabled { "true" } else { "false" }, ) - .map_err(|e| e.to_string()) + .map_err(|e| crate::error::AppError::db_query_failed(e.to_string())) } /// Verify FTS5 is available (release gate command)