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/context/menu_context.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/context/menu_context.go')
-rw-r--r-- | pkg/gui/context/menu_context.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go index 6d87d2bb7..e4c3d7280 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -1,6 +1,8 @@ package context import ( + "errors" + "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -148,7 +150,7 @@ func (self *MenuContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Bin func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error { if selectedItem != nil && selectedItem.DisabledReason != nil { if selectedItem.DisabledReason.ShowErrorInPanel { - return self.c.ErrorMsg(selectedItem.DisabledReason.Text) + return errors.New(selectedItem.DisabledReason.Text) } self.c.ErrorToast(self.c.Tr.DisabledMenuItemPrefix + selectedItem.DisabledReason.Text) |