diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-04-18 10:14:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 10:14:51 +0200 |
commit | 34f8f7293c5c901461a26f09839ebe5f0dd79869 (patch) | |
tree | 4b65b46c7d1e32f1d8e90b528545b081b0fd8822 /pkg/gui/controllers/undo_controller.go | |
parent | 145795c0b07da129599506ac8827a16314456ac4 (diff) | |
parent | caad55350252793b53aaf699062644a2cddc6a08 (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/undo_controller.go')
-rw-r--r-- | pkg/gui/controllers/undo_controller.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/pkg/gui/controllers/undo_controller.go b/pkg/gui/controllers/undo_controller.go index 2df3b8689..96e9f3f11 100644 --- a/pkg/gui/controllers/undo_controller.go +++ b/pkg/gui/controllers/undo_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "errors" "fmt" "github.com/jesseduffield/gocui" @@ -78,7 +79,7 @@ func (self *UndoController) reflogUndo() error { undoingStatus := self.c.Tr.UndoingStatus if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { - return self.c.ErrorMsg(self.c.Tr.CantUndoWhileRebasing) + return errors.New(self.c.Tr.CantUndoWhileRebasing) } return self.parseReflogForActions(func(counter int, action reflogAction) (bool, error) { @@ -126,7 +127,7 @@ func (self *UndoController) reflogRedo() error { redoingStatus := self.c.Tr.RedoingStatus if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { - return self.c.ErrorMsg(self.c.Tr.CantRedoWhileRebasing) + return errors.New(self.c.Tr.CantRedoWhileRebasing) } return self.parseReflogForActions(func(counter int, action reflogAction) (bool, error) { @@ -234,10 +235,7 @@ type hardResetOptions struct { // only to be used in the undo flow for now (does an autostash) func (self *UndoController) hardResetWithAutoStash(commitHash string, options hardResetOptions) error { reset := func() error { - if err := self.c.Helpers().Refs.ResetToRef(commitHash, "hard", options.EnvVars); err != nil { - return self.c.Error(err) - } - return nil + return self.c.Helpers().Refs.ResetToRef(commitHash, "hard", options.EnvVars) } // if we have any modified tracked files we need to ask the user if they want us to stash for them @@ -250,20 +248,17 @@ func (self *UndoController) hardResetWithAutoStash(commitHash string, options ha HandleConfirm: func() error { return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error { if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitHash); err != nil { - return self.c.Error(err) + return err } if err := reset(); err != nil { return err } err := self.c.Git().Stash.Pop(0) - if err := self.c.Refresh(types.RefreshOptions{}); err != nil { - return err - } if err != nil { - return self.c.Error(err) + return err } - return nil + return self.c.Refresh(types.RefreshOptions{}) }) }, }) |