Restore the terminal if a goroutine panics

Most goroutines run their function through utils.Safe, which closes
the screen if the function panics. Without it, the panic is printed to
a terminal that is still in raw mode and on the alternate screen, and
the terminal needs a reset afterwards. Go has no process-wide hook for
panics, so every goroutine has to do this itself.

Use utils.Safe for the goroutines that don't use it yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-10-14 20:28:53 +02:00
1 parent 6042e1c28b
commit 73fac4a554
10 files changed
+23 -20

No files matched your search

+4 -4
View File
@@ -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 {
+2 -2
View File
@@ -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()
@@ -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)
}
}
}()
})
}