From 3e2ac3e7bc04099c6fad34a6a5dd55fb0295c495 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Wed, 2 Apr 2025 13:15:35 -0400 Subject: [PATCH] Log error and proceed when failing to load repo environment (#27938) Closes #ISSUE Release Notes: - N/A --- crates/project/src/environment.rs | 13 ++++++++++++- crates/project/src/git_store.rs | 9 +++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/project/src/environment.rs b/crates/project/src/environment.rs index aee8fbb6e8ec63eb86f43120771e11e2753ead69..7815642cbef3a53c2d7e76d30ec12c824079e66a 100644 --- a/crates/project/src/environment.rs +++ b/crates/project/src/environment.rs @@ -60,7 +60,7 @@ impl ProjectEnvironment { } } - /// Returns an iterator over all pairs `(worktree_id, error_message)` of + /// Returns an iterator over all pairs `(abs_path, error_message)` of /// environment errors associated with this project environment. pub(crate) fn environment_errors( &self, @@ -144,8 +144,15 @@ impl From for String { } } +#[derive(Debug)] pub struct EnvironmentErrorMessage(pub String); +impl std::fmt::Display for EnvironmentErrorMessage { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + impl EnvironmentErrorMessage { #[allow(dead_code)] fn from_str(s: &str) -> Self { @@ -361,6 +368,10 @@ fn get_directory_env( if let Some(error) = error_message { this.update(cx, |this, cx| { + log::error!( + "error fetching environment for path {abs_path:?}: {}", + error + ); this.environment_error_messages.insert(abs_path, error); cx.emit(ProjectEnvironmentEvent::ErrorsUpdated) }) diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs index e0215707e74ef637fa674710d5d4c473609b443e..f5ccf93947802b06e6d03618a96c2fd3ba168b3b 100644 --- a/crates/project/src/git_store.rs +++ b/crates/project/src/git_store.rs @@ -3632,12 +3632,13 @@ impl Repository { .upgrade() .ok_or_else(|| anyhow!("missing project environment"))? .update(cx, |project_environment, cx| { - project_environment.get_environment(Some(work_directory_abs_path), cx) + project_environment.get_environment(Some(work_directory_abs_path.clone()), cx) })? .await - .ok_or_else(|| { - anyhow!("failed to get environment for repository working directory") - })?; + .unwrap_or_else(|| { + log::error!("failed to get working directory environment for repository {work_directory_abs_path:?}"); + HashMap::default() + }); let backend = cx .background_spawn(async move { fs.open_repo(&dot_git_abs_path)