From adc252901944e84433cb8a50de9b114ba120282d Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 18 Feb 2019 19:42:23 +1100 Subject: dealing better with errors at the top level --- pkg/app/app.go | 8 ++++++-- pkg/gui/gui.go | 8 +++----- pkg/i18n/dutch.go | 3 +++ pkg/i18n/english.go | 3 +++ pkg/i18n/polish.go | 3 +++ 5 files changed, 18 insertions(+), 7 deletions(-) (limited to 'pkg') diff --git a/pkg/app/app.go b/pkg/app/app.go index ad5edca70..54706682c 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -78,8 +78,8 @@ func newLogger(config config.AppConfigurer) *logrus.Entry { }) } -// Setup bootstrap a new application -func Setup(config config.AppConfigurer) (*App, error) { +// NewApp bootstrap a new application +func NewApp(config config.AppConfigurer) (*App, error) { app := &App{ closers: []io.Closer{}, Config: config, @@ -105,6 +105,10 @@ func Setup(config config.AppConfigurer) (*App, error) { return app, nil } +func (app *App) Run() error { + return app.Gui.RunWithSubprocesses() +} + // Close closes any resources func (app *App) Close() error { for _, closer := range app.closers { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f001a8113..11daec652 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -7,7 +7,6 @@ import ( // "io/ioutil" "io/ioutil" - "log" "os" "os/exec" "strings" @@ -577,7 +576,7 @@ func (gui *Gui) Run() error { // RunWithSubprocesses loops, instantiating a new gocui.Gui with each iteration // if the error returned from a run is a ErrSubProcess, it runs the subprocess // otherwise it handles the error, possibly by quitting the application -func (gui *Gui) RunWithSubprocesses() { +func (gui *Gui) RunWithSubprocesses() error { for { if err := gui.Run(); err != nil { if err == gocui.ErrQuit { @@ -594,12 +593,11 @@ func (gui *Gui) RunWithSubprocesses() { gui.SubProcess.Stdin = nil gui.SubProcess = nil } else { - newErr := errors.Wrap(err, 0) - stackTrace := newErr.ErrorStack() - log.Panicln(stackTrace) + return err } } } + return nil } func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error { diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 2c39cd435..851febcac 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -478,6 +478,9 @@ func addDutch(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "FwdCommitsToPush", Other: "Cannot fast-forward a branch with commits to push", + }, &i18n.Message{ + ID: "ErrorOccurred", + Other: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues", }, ) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 788897c31..d7b509861 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -522,6 +522,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "FwdCommitsToPush", Other: "Cannot fast-forward a branch with commits to push", + }, &i18n.Message{ + ID: "ErrorOccurred", + Other: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues", }, ) } diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index c37fe3dd9..205ec9d6c 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -461,6 +461,9 @@ func addPolish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "FwdCommitsToPush", Other: "Cannot fast-forward a branch with commits to push", + }, &i18n.Message{ + ID: "ErrorOccurred", + Other: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazygit/issues", }, ) } -- cgit v1.2.3