Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Consistently use `context()` to preserve sources for anyhow errors (#59112)
Tom Houlé2ab35c6b7d59
diff --git a/crates/agent/src/db.rs b/crates/agent/src/db.rsindex 7d69e03c325..a09aa9c2c13 100644--- a/crates/agent/src/db.rs+++ b/crates/agent/src/db.rs@@ -2,7 +2,7 @@ use crate::{AgentMessage, AgentMessageContent, UserMessage, UserMessageContent};use acp_thread::ClientUserMessageId;use agent_client_protocol::schema::v1 as acp;use agent_settings::AgentProfileId;-use anyhow::{Result, anyhow};+use anyhow::Result;use chrono::{DateTime, Utc};use collections::{HashMap, IndexMap};use futures::{FutureExt, future::Shared};@@ -444,7 +444,7 @@ impl ThreadsDatabase {data BLOB NOT NULL)"})?()- .map_err(|e| anyhow!("Failed to create threads table: {}", e))?;+ .map_err(|e| e.context("Failed to create threads table"))?;if let Ok(mut s) = connection.exec(indoc! {"ALTER TABLE threads ADD COLUMN parent_id TEXTdiff --git a/crates/keymap_editor/src/keymap_editor.rs b/crates/keymap_editor/src/keymap_editor.rsindex aecaea7fcba..db405135994 100644--- a/crates/keymap_editor/src/keymap_editor.rs+++ b/crates/keymap_editor/src/keymap_editor.rs@@ -3668,7 +3668,7 @@ async fn save_keybinding_update(keyboard_mapper,deprecated_aliases,)- .map_err(|err| anyhow::anyhow!("Could not save updated keybinding: {}", err))?;+ .map_err(|err| err.context("Could not save updated keybinding"))?;fs.write(paths::keymap_file().as_path(),updated_keymap_contents.as_bytes(),diff --git a/crates/remote/src/transport/ssh.rs b/crates/remote/src/transport/ssh.rsindex 25946c0b7c0..f897bdd1d96 100644--- a/crates/remote/src/transport/ssh.rs+++ b/crates/remote/src/transport/ssh.rs@@ -496,7 +496,9 @@ impl RemoteConnection for SshRemoteConnection {{Ok(process) => process,Err(error) => {- return Task::ready(Err(anyhow!("failed to spawn remote server: {}", error)));+ return Task::ready(Err(+ anyhow::Error::new(error).context("failed to spawn remote server")+ ));}};diff --git a/crates/remote/src/transport/wsl.rs b/crates/remote/src/transport/wsl.rsindex 21ebdcbd049..9b8e7763944 100644--- a/crates/remote/src/transport/wsl.rs+++ b/crates/remote/src/transport/wsl.rs@@ -210,7 +210,7 @@ impl WslRemoteConnection {let mkdir = self.shell_kind.prepend_command_prefix("mkdir");self.run_wsl_command(&mkdir, &["-p", &parent]).await- .map_err(|e| anyhow!("Failed to create directory: {}", e))?;+ .map_err(|e| e.context("Failed to create directory"))?;}let binary_exists_on_server = self@@ -346,7 +346,7 @@ impl WslRemoteConnection {self.run_wsl_command("sh", &["-c", &script]).await- .map_err(|e| anyhow!("Failed to extract server binary: {}", e))?;+ .map_err(|e| e.context("Failed to extract server binary"))?;Ok(())}}@@ -395,7 +395,9 @@ impl RemoteConnection for WslRemoteConnection {{Ok(process) => process,Err(error) => {- return Task::ready(Err(anyhow!("failed to spawn remote server: {}", error)));+ return Task::ready(Err(+ anyhow::Error::new(error).context("failed to spawn remote server")+ ));}};