Refactor: Migrate unwrap calls to AppError in MCP handlers

This commit is contained in:
Riz Ashraf committed 2026-09-30 21:02:50 +01:00
1 parent 4e1a633dbd
commit 0e866f2465
12 files changed
+276 -326

No files matched your search

+5 -5
View File
@@ -21,10 +21,10 @@ impl McpTool for GetActiveWorktreeContextHandler {
)
}
async fn execute(&self, _args: Value, _state: Arc<MemoryState>) -> Result<String, String> {
let result = tokio::task::spawn_blocking(move || -> Result<Value, String> {
async fn execute(&self, _args: Value, _state: Arc<MemoryState>) -> crate::error::Result<String> {
let result = tokio::task::spawn_blocking(move || -> crate::error::Result<serde_json::Value> {
let cwd = env::current_dir().map_err(|e| e.to_string())?;
let repo = git2::Repository::discover(&cwd).map_err(|e| format!("Not in a git repository: {}", e))?;
let repo = git2::Repository::discover(&cwd).map_err(|e| crate::error::AppError::Internal(format!("Not in a git repository: {}", e)))?;
let mut branch_name = String::new();
if let Ok(head) = repo.head()
@@ -70,8 +70,8 @@ impl McpTool for GetActiveWorktreeContextHandler {
}))
})
.await
.map_err(|e| format!("Task panic: {}", e))??;
.map_err(|e| crate::error::AppError::Internal(format!("Task panic: {}", e)))??;
Ok(serde_json::to_string_pretty(&result).unwrap())
Ok::<String, crate::error::AppError>(serde_json::to_string_pretty(&result)?)
}
}