Log error and proceed when failing to load repo environment (#27938)

Closes #ISSUE

Release Notes:

- N/A
This commit is contained in:
Cole Miller 2025-04-02 13:15:35 -04:00 committed by GitHub
parent 646f65511c
commit 3e2ac3e7bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View file

@ -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. /// environment errors associated with this project environment.
pub(crate) fn environment_errors( pub(crate) fn environment_errors(
&self, &self,
@ -144,8 +144,15 @@ impl From<EnvironmentOrigin> for String {
} }
} }
#[derive(Debug)]
pub struct EnvironmentErrorMessage(pub String); 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 { impl EnvironmentErrorMessage {
#[allow(dead_code)] #[allow(dead_code)]
fn from_str(s: &str) -> Self { fn from_str(s: &str) -> Self {
@ -361,6 +368,10 @@ fn get_directory_env(
if let Some(error) = error_message { if let Some(error) = error_message {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
log::error!(
"error fetching environment for path {abs_path:?}: {}",
error
);
this.environment_error_messages.insert(abs_path, error); this.environment_error_messages.insert(abs_path, error);
cx.emit(ProjectEnvironmentEvent::ErrorsUpdated) cx.emit(ProjectEnvironmentEvent::ErrorsUpdated)
}) })

View file

@ -3632,12 +3632,13 @@ impl Repository {
.upgrade() .upgrade()
.ok_or_else(|| anyhow!("missing project environment"))? .ok_or_else(|| anyhow!("missing project environment"))?
.update(cx, |project_environment, cx| { .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 .await
.ok_or_else(|| { .unwrap_or_else(|| {
anyhow!("failed to get environment for repository working directory") log::error!("failed to get working directory environment for repository {work_directory_abs_path:?}");
})?; HashMap::default()
});
let backend = cx let backend = cx
.background_spawn(async move { .background_spawn(async move {
fs.open_repo(&dot_git_abs_path) fs.open_repo(&dot_git_abs_path)