diff --git a/pkg/app/errors.go b/pkg/app/errors.go index 506fec276e2..ee50d30c2d6 100644 --- a/pkg/app/errors.go +++ b/pkg/app/errors.go @@ -27,6 +27,10 @@ func knownError(tr *i18n.TranslationSet, err error) (string, bool) { originalError: "fatal: not a git repository", newError: tr.NotARepository, }, + { + originalError: "fatal: Unable to read current working directory", + newError: tr.WorkingDirectoryDoesNotExist, + }, { originalError: "getwd: no such file or directory", newError: tr.WorkingDirectoryDoesNotExist, diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go index a4e41b75604..071df8f281f 100644 --- a/pkg/commands/git_commands/branch_loader.go +++ b/pkg/commands/git_commands/branch_loader.go @@ -72,7 +72,10 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit, onWorker func(func() error), renderFunc func(), ) ([]*models.Branch, error) { - branches := self.obtainBranches() + branches, err := self.obtainBranches() + if err != nil { + return nil, err + } if self.UserConfig().Git.LocalBranchSortOrder == "recency" { reflogBranches := self.obtainReflogBranches(reflogCommits) @@ -232,10 +235,10 @@ func (self *BranchLoader) GetBaseBranch(branch *models.Branch, mainBranches *Mai return split[0], nil } -func (self *BranchLoader) obtainBranches() []*models.Branch { +func (self *BranchLoader) obtainBranches() ([]*models.Branch, error) { output, err := self.getRawBranches() if err != nil { - panic(err) + return nil, err } trimmedOutput := strings.TrimSpace(output) @@ -256,7 +259,7 @@ func (self *BranchLoader) obtainBranches() []*models.Branch { storeCommitDateAsRecency := self.UserConfig().Git.LocalBranchSortOrder != "recency" return obtainBranch(split, storeCommitDateAsRecency), true - }) + }), nil } func (self *BranchLoader) getRawBranches() (string, error) { diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 332b3809125..b29bf160771 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -471,7 +471,10 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele }) }) if err != nil { - self.c.Log.Error(err) + self.c.OnUIThread(func() error { + return types.ErrFatal{Err: err} + }) + return } prevSelectedBranch := self.c.Contexts().Branches.GetSelected() diff --git a/pkg/gui/popup/popup_handler.go b/pkg/gui/popup/popup_handler.go index d8824016f48..27d9c863fc8 100644 --- a/pkg/gui/popup/popup_handler.go +++ b/pkg/gui/popup/popup_handler.go @@ -81,6 +81,11 @@ func (self *PopupHandler) WithWaitingStatusSync(message string, f func() error) } func (self *PopupHandler) ErrorHandler(err error) error { + var fatalError types.ErrFatal + if errors.As(err, &fatalError) { + return err + } + var notHandledError *types.ErrKeybindingNotHandled if errors.As(err, ¬HandledError) { if !notHandledError.DisabledReason.ShowErrorInPanel { diff --git a/pkg/gui/types/keybindings.go b/pkg/gui/types/keybindings.go index 9289dbe9a5f..955b317d81d 100644 --- a/pkg/gui/types/keybindings.go +++ b/pkg/gui/types/keybindings.go @@ -92,3 +92,17 @@ func (e ErrKeybindingNotHandled) Error() string { func (e ErrKeybindingNotHandled) Unwrap() error { return gocui.ErrKeybindingNotHandled } + +// ErrFatal is an error that should cause the program to exit immediately, +// bypassing the popup error handler. +type ErrFatal struct { + Err error +} + +func (e ErrFatal) Error() string { + return e.Err.Error() +} + +func (e ErrFatal) Unwrap() error { + return e.Err +}