From c90bf6e6b7c0c792b91dd7eeb7d725cf74c1b234 Mon Sep 17 00:00:00 2001 From: Jakub Charvat Date: Fri, 27 Mar 2026 14:06:21 +0100 Subject: [PATCH] Fix unformatted error contexts (#52568) When debugging a remote SSH connection, I came across an unformatted format string in the output log. I changed the raw `.context(fmt)` call to a `.with_context(|| format!(fmt))`. I ran a quick sweep through the codebase to identify and fix two other instances of the same issue. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - N/A --- crates/extension_host/src/headless_host.rs | 2 +- crates/language_models/src/provider/bedrock.rs | 2 +- crates/project/src/lsp_command.rs | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/extension_host/src/headless_host.rs b/crates/extension_host/src/headless_host.rs index 0aff06fdddcf5c075bd669528b5c52137f745863..7c30228257dbaa037fbc772be822a1000adfdfef 100644 --- a/crates/extension_host/src/headless_host.rs +++ b/crates/extension_host/src/headless_host.rs @@ -281,7 +281,7 @@ impl HeadlessExtensionStore { fs.rename(&tmp_path, &path, RenameOptions::default()) .await - .context("Failed to rename {tmp_path:?} to {path:?}")?; + .with_context(|| format!("Failed to rename {tmp_path:?} to {path:?}"))?; Self::load_extension(this, extension, cx).await }) diff --git a/crates/language_models/src/provider/bedrock.rs b/crates/language_models/src/provider/bedrock.rs index 734e97ee335c4106fced9d334d31b5ed5b86d407..f53f145dbd387aa948b977d854ba77f1cbe49ded 100644 --- a/crates/language_models/src/provider/bedrock.rs +++ b/crates/language_models/src/provider/bedrock.rs @@ -344,7 +344,7 @@ impl State { .ok_or(AuthenticateError::CredentialsNotFound)?; let credentials_str = String::from_utf8(credentials_bytes) - .context("invalid {PROVIDER_NAME} credentials")?; + .with_context(|| format!("invalid {PROVIDER_NAME} credentials"))?; let credentials: BedrockCredentials = serde_json::from_str(&credentials_str).context("failed to parse credentials")?; diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rs index 59baaa156e64c744d8906d294f7f3978280a1839..d4a4f9b04968413c51607f71047752a9b779b79a 100644 --- a/crates/project/src/lsp_command.rs +++ b/crates/project/src/lsp_command.rs @@ -3215,8 +3215,9 @@ impl InlayHints { Some(((uri, range), server_id)) => Some(( LanguageServerId(server_id as usize), lsp::Location { - uri: lsp::Uri::from_str(&uri) - .context("invalid uri in hint part {part:?}")?, + uri: lsp::Uri::from_str(&uri).with_context(|| { + format!("invalid uri in hint part {uri:?}") + })?, range: lsp::Range::new( point_to_lsp(PointUtf16::new( range.start.row,