From af4c70fbbc26f00a96442aabda17cc36e8d6eefc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 20 Jul 2024 22:01:16 +0200 Subject: [PATCH 1/2] propagate fetch-errors explicitly to prevent silent failures (#4389) However, some tuning might be desired to prevent showing anything if background-fetches fail, which might be desirable after all as they don't seem to run with modals enabled. Also perform minor refactors while at it. --- .../gitbutler-branch-actions/src/actions.rs | 29 +++++++++---------- .../gitbutler-tauri/src/virtual_branches.rs | 8 +++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/gitbutler-branch-actions/src/actions.rs b/crates/gitbutler-branch-actions/src/actions.rs index a825e7f4e5..181c7ef64a 100644 --- a/crates/gitbutler-branch-actions/src/actions.rs +++ b/crates/gitbutler-branch-actions/src/actions.rs @@ -428,26 +428,23 @@ impl VirtualBranchActions { let helper = Helper::default(); let remotes = project_repository.repo().remotes_as_string()?; - let fetch_results: Vec> = remotes + let fetch_errors: Vec<_> = remotes .iter() - .map(|remote| project_repository.fetch(remote, &helper, askpass.clone())) + .filter_map(|remote| { + project_repository + .fetch(remote, &helper, askpass.clone()) + .err() + .map(|err| err.to_string()) + }) .collect(); - let project_data_last_fetched = if fetch_results.iter().any(Result::is_err) { - FetchResult::Error { - timestamp: std::time::SystemTime::now(), - error: fetch_results - .iter() - .filter_map(|result| match result { - Ok(_) => None, - Err(error) => Some(error.to_string()), - }) - .collect::>() - .join("\n"), - } + let timestamp = std::time::SystemTime::now(); + let project_data_last_fetched = if fetch_errors.is_empty() { + FetchResult::Fetched { timestamp } } else { - FetchResult::Fetched { - timestamp: std::time::SystemTime::now(), + FetchResult::Error { + timestamp, + error: fetch_errors.join("\n"), } }; diff --git a/crates/gitbutler-tauri/src/virtual_branches.rs b/crates/gitbutler-tauri/src/virtual_branches.rs index 46bbd79c22..60009bb0cd 100644 --- a/crates/gitbutler-tauri/src/virtual_branches.rs +++ b/crates/gitbutler-tauri/src/virtual_branches.rs @@ -9,7 +9,7 @@ pub mod commands { use gitbutler_branch_actions::{RemoteBranch, RemoteBranchData}; use gitbutler_error::error::Code; use gitbutler_project as projects; - use gitbutler_project::ProjectId; + use gitbutler_project::{FetchResult, ProjectId}; use gitbutler_reference::normalize_branch_name as normalize_name; use gitbutler_reference::ReferenceName; use gitbutler_reference::{Refname, RemoteRefname}; @@ -478,12 +478,16 @@ pub mod commands { projects .update(&projects::UpdateRequest { id: project.id, - project_data_last_fetched: Some(project_data_last_fetched), + project_data_last_fetched: Some(project_data_last_fetched.clone()), ..Default::default() }) .await .context("failed to update project with last fetched timestamp")?; + if let FetchResult::Error { error, .. } = project_data_last_fetched { + return Err(anyhow!(error).into()); + } + let base_branch = VirtualBranchActions::get_base_branch_data(&project).await?; Ok(base_branch) } From 5cfa2fd4df8af6a0cc08fb0c45539cab90e74f93 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 20 Jul 2024 22:43:28 +0200 Subject: [PATCH 2/2] Avoid showing any errors for background fetches Otherwise these could pile up or be distracting. However, errors should be shown on specific user actions that allow for modal dialogues. --- app/src/lib/baseBranch/baseBranchService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/lib/baseBranch/baseBranchService.ts b/app/src/lib/baseBranch/baseBranchService.ts index aa14f7e748..3cf5b342b1 100644 --- a/app/src/lib/baseBranch/baseBranchService.ts +++ b/app/src/lib/baseBranch/baseBranchService.ts @@ -45,7 +45,7 @@ export class BaseBranchService { return; } else if (err.code === Code.ProjectsGitAuth) { showError('Failed to authenticate', err); - } else { + } else if (action !== undefined) { showError('Failed to fetch', err); } console.error(err);