Fix unformatted error contexts (#52568)

Jakub Charvat created

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

Change summary

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(-)

Detailed changes

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
         })

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")?;

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,