Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions pkg/commands/git_commands/branch_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions pkg/gui/popup/popup_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &notHandledError) {
if !notHandledError.DisabledReason.ShowErrorInPanel {
Expand Down
14 changes: 14 additions & 0 deletions pkg/gui/types/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading