diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index c8a06832c..d69e7f4ab 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -166,11 +166,11 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes } if cliArgs.Profile { - go func() { + go utils.Safe(func() { if err := http.ListenAndServe("localhost:6060", nil); err != nil { log.Fatal(err) } - }() + }) } parsedGitArg := parseGitArg(cliArgs.GitArg) diff --git a/pkg/commands/oscommands/pty_windows.go b/pkg/commands/oscommands/pty_windows.go index b36342e61..54fd9da78 100644 --- a/pkg/commands/oscommands/pty_windows.go +++ b/pkg/commands/oscommands/pty_windows.go @@ -207,7 +207,7 @@ func (p *winPty) Close() error { func startWaiter(proc *os.Process, p *winPty) func() error { done := make(chan struct{}) var waitErr error - go func() { + go utils.Safe(func() { defer close(done) state, err := proc.Wait() p.closeHpc() @@ -218,7 +218,7 @@ func startWaiter(proc *os.Process, p *winPty) func() error { if !state.Success() { waitErr = fmt.Errorf("exit status %d", state.ExitCode()) } - }() + }) return func() error { <-done return waitErr diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index e998c2ad1..bac22a209 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -280,13 +280,13 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string, }) } - go func() { + go utils.Safe(func() { // We don't care about the error here, we'll check it later (in the // return statement below). Here we only wait for all the goroutines to // finish so that we can close the channel. _ = errg.Wait() close(hashChan) - }() + }) result := set.New[string]() for hash := range hashChan { @@ -343,13 +343,13 @@ func (self *FixupHelper) blameAddedLines(commits []*models.Commit, addedLineHunk }) } - go func() { + go utils.Safe(func() { // We don't care about the error here, we'll check it later (in the // return statement below). Here we only wait for all the goroutines to // finish so that we can close the channel. _ = errg.Wait() close(hashesChan) - }() + }) result := set.New[string]() for hashes := range hashesChan { diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index 53018a2e1..00cfbbd0a 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -324,10 +324,10 @@ func (self *ReposHelper) CreateRecentReposMenu() error { wg.Add(len(recentRepoPaths)) for i, path := range recentRepoPaths { - go func() { + go utils.Safe(func() { defer wg.Done() currentBranches[i] = self.getCurrentBranch(path) - }() + }) } wg.Wait() diff --git a/pkg/gui/controllers/helpers/signal_handling.go b/pkg/gui/controllers/helpers/signal_handling.go index 40d04f689..be7ce44e4 100644 --- a/pkg/gui/controllers/helpers/signal_handling.go +++ b/pkg/gui/controllers/helpers/signal_handling.go @@ -7,6 +7,7 @@ import ( "os/signal" "syscall" + "github.com/jesseduffield/lazygit/pkg/utils" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) @@ -45,7 +46,7 @@ func handleResumeSignal(log *logrus.Entry, onResume func() error) { } func installResumeSignalHandler(log *logrus.Entry, onResume func() error) { - go func() { + go utils.Safe(func() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGCONT) @@ -55,5 +56,5 @@ func installResumeSignalHandler(log *logrus.Entry, onResume func() error) { handleResumeSignal(log, onResume) } } - }() + }) } diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index a8e0a1c67..6f437f675 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -80,7 +80,7 @@ func RenderAux(pipeSets [][]Pipe, commits []*models.Commit, selectedCommitHashPt wg.Add(maxProcs) for i := range maxProcs { - go func() { + go utils.Safe(func() { from := i * perProc to := (i + 1) * perProc if i == maxProcs-1 { @@ -98,7 +98,7 @@ func RenderAux(pipeSets [][]Pipe, commits []*models.Commit, selectedCommitHashPt } chunks[i] = innerLines wg.Done() - }() + }) } wg.Wait() diff --git a/pkg/gui/status/status_manager.go b/pkg/gui/status/status_manager.go index 35e1b7746..dfcb2994f 100644 --- a/pkg/gui/status/status_manager.go +++ b/pkg/gui/status/status_manager.go @@ -7,6 +7,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" "github.com/sasha-s/go-deadlock" ) @@ -64,12 +65,12 @@ func (self *StatusManager) WithWaitingStatus(message string, renderFunc func(), func (self *StatusManager) AddToastStatus(message string, kind types.ToastKind) int { id := self.addStatus(message, "toast", kind) - go func() { + go utils.Safe(func() { delay := lo.Ternary(kind == types.ToastKindError, time.Second*4, time.Second*2) time.Sleep(delay) self.removeStatus(id) - }() + }) return id } diff --git a/pkg/gui/test_mode.go b/pkg/gui/test_mode.go index 2644e989b..b3f0f9fb2 100644 --- a/pkg/gui/test_mode.go +++ b/pkg/gui/test_mode.go @@ -28,7 +28,7 @@ func (gui *Gui) handleTestMode() { gui.c.GocuiGui().WaitUntilIdle() } - go func() { + go utils.Safe(func() { waitUntilIdle() toastChan := make(chan string, 100) @@ -43,7 +43,7 @@ func (gui *Gui) handleTestMode() { // Wait for the event loop to actually exit. <-gui.g.LoopExited() - }() + }) if os.Getenv(components.WAIT_FOR_DEBUGGER_ENV_VAR) == "" { timeout := 40 * time.Second * testTimeoutMultiplier diff --git a/pkg/snake/snake.go b/pkg/snake/snake.go index 7dd2e079c..d19c25d45 100644 --- a/pkg/snake/snake.go +++ b/pkg/snake/snake.go @@ -4,6 +4,7 @@ import ( "math/rand" "time" + "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" ) @@ -77,7 +78,7 @@ func NewGame(width, height int, render func(cells [][]CellType, alive bool), log } func (self *Game) Start() { - go self.gameLoop() + go utils.Safe(self.gameLoop) } func (self *Game) Exit() { diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index 37f586222..a7d0fafd9 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -818,7 +818,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (Cmd, io.Reader), prefix // the process takes a while until it actually terminates. We still want to call // Wait to reclaim any resources, but do it on a background goroutine, and ignore // any errors. - go func() { _ = cmd.Wait() }() + go utils.Safe(func() { _ = cmd.Wait() }) default: if err := cmd.Wait(); err != nil { self.Log.Errorf("Unexpected error when running cmd task: %v; Failed command: %v", err, cmd.String())