summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers/bisect_controller.go
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-04-18 10:14:51 +0200
committerGitHub <noreply@github.com>2024-04-18 10:14:51 +0200
commit34f8f7293c5c901461a26f09839ebe5f0dd79869 (patch)
tree4b65b46c7d1e32f1d8e90b528545b081b0fd8822 /pkg/gui/controllers/bisect_controller.go
parent145795c0b07da129599506ac8827a16314456ac4 (diff)
parentcaad55350252793b53aaf699062644a2cddc6a08 (diff)
Simplify error handling (#3502)
- **PR Description** Simplify and canonicalize error handling across the code base. Previously it was important to make sure that errors don't bubble up into gocui, because it would panic there; so we had to show errors in error panels in the right places (in controller code, usually). This is error-prone because it's easy to forget (see #3490 for an example); also, it's not always obvious where in the call chain the error panel needs to be shown. Most of the time it's in controller code, but we had plenty of calls to `Error()` in helpers, and I remember that I found this very confusing when I was new to the code base. Change this so that you can simply return errors everywhere. The functions to show an error message manually have been removed for clarity. I tried to structure the commits so that you can review them one by one. Closes #3491.
Diffstat (limited to 'pkg/gui/controllers/bisect_controller.go')
-rw-r--r--pkg/gui/controllers/bisect_controller.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go
index 89cc6241f..0db570107 100644
--- a/pkg/gui/controllers/bisect_controller.go
+++ b/pkg/gui/controllers/bisect_controller.go
@@ -96,7 +96,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(hashToMark, info.NewTerm()); err != nil {
- return self.c.Error(err)
+ return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
@@ -109,7 +109,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(hashToMark, info.OldTerm()); err != nil {
- return self.c.Error(err)
+ return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
@@ -122,7 +122,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(hashToMark); err != nil {
- return self.c.Error(err)
+ return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
@@ -137,7 +137,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(commit.Hash); err != nil {
- return self.c.Error(err)
+ return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
@@ -169,11 +169,11 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.Start(); err != nil {
- return self.c.Error(err)
+ return err
}
if err := self.c.Git().Bisect.Mark(commit.Hash, info.NewTerm()); err != nil {
- return self.c.Error(err)
+ return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
@@ -186,11 +186,11 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.Start(); err != nil {
- return self.c.Error(err)
+ return err
}
if err := self.c.Git().Bisect.Mark(commit.Hash, info.OldTerm()); err != nil {
- return self.c.Error(err)
+ return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
@@ -209,7 +209,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
HandleConfirm: func(newTerm string) error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.StartWithTerms(oldTerm, newTerm); err != nil {
- return self.c.Error(err)
+ return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
@@ -232,7 +232,7 @@ func (self *BisectController) showBisectCompleteMessage(candidateHashes []string
formattedCommits, err := self.c.Git().Commit.GetCommitsOneline(candidateHashes)
if err != nil {
- return self.c.Error(err)
+ return err
}
return self.c.Confirm(types.ConfirmOpts{
@@ -241,7 +241,7 @@ func (self *BisectController) showBisectCompleteMessage(candidateHashes []string
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.ResetBisect)
if err := self.c.Git().Bisect.Reset(); err != nil {
- return self.c.Error(err)
+ return err
}
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
@@ -252,11 +252,11 @@ func (self *BisectController) showBisectCompleteMessage(candidateHashes []string
func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool) error {
done, candidateHashes, err := self.c.Git().Bisect.IsDone()
if err != nil {
- return self.c.Error(err)
+ return err
}
if err := self.afterBisectMarkRefresh(selectCurrent, waitToReselect); err != nil {
- return self.c.Error(err)
+ return err
}
if done {
@@ -267,16 +267,17 @@ func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool)
}
func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToReselect bool) error {
- selectFn := func() {
+ selectFn := func() error {
if selectCurrent {
self.selectCurrentBisectCommit()
}
+ return nil
}
if waitToReselect {
return self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{}, Then: selectFn})
} else {
- selectFn()
+ _ = selectFn()
return self.c.Helpers().Bisect.PostBisectCommandRefresh()
}