From 8e045653bef18ef356d989b17e3eac39b42e463e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 19 Jul 2026 22:34:08 +0200 Subject: [PATCH] Don't pop up errors from a refresh worker once the repo was switched MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An error returned from a gocui worker is shown to the user in an error popup. For the branch loader's behind-counts worker that used to be the "no such ref" popup when a background refresh crossed a repo switch: the old repo's main branch didn't exist in the new repo. The previous commits fix that scenario properly — the command now runs against the repo the refresh was started for — but a stale worker can still fail legitimately, most plausibly because that repo was deleted after switching away from it (e.g. removing a worktree). Its results are dropped anyway, so log the error instead of alarming the user about a repo they already left. Co-Authored-By: Claude Fable 5 --- pkg/gui/controllers/helpers/refresh_helper.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index caf14ed2a..7ae7b4119 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1039,7 +1039,18 @@ func (self *RefreshHelper) refreshBranches(captured capturedBranchState, refresh loadBehindCounts, func(f func() error) { self.onWorker(env.background, func(_ gocui.Task) error { - return f() + err := f() + if err != nil && self.c.State().GetRepoGeneration() != env.generation { + // An error returned from a worker is shown in a popup. Don't + // do that if the repo was switched while this worker was in + // flight: its results are dropped anyway, and the error + // concerns a repo the user has already left — e.g. failing to + // compute the behind-counts for a worktree that was deleted + // after switching away from it. + self.c.Log.Warnf("dropping error from a stale refresh worker after a repo switch: %v", err) + return nil + } + return err }) }, func() {