jesseduffield / jesseduffield/lazygit

Panics can sometimes cause terminal issues

Open
#956 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

**Describe the bug**
When lazygit panics from inside a goroutine, termbox is never asked to return the terminal back to its original state, meaning weird things can happen like printing characters when you click or scroll your mouse

**To Reproduce**
Create a goroutine and panic from within it, then see how your terminal responds to mouse clicks. I tested by panicking from escape.go in the gocui fork which itself was run inside a task from tasks.go

**Expected behavior**
terminal returns to normal state

**Screenshots**
![image](https://user-images.githubusercontent.com/8456633/90976662-18a1fd80-e582-11ea-8a5f-c6b9db82e8ee.png)

**Desktop (please complete the following information):**
- OS: OSX
- Lazygit Version commit d2d88fe6

**Additional context**
There's no way to recover from every goroutine, we might need some recovery boilerplate inside every goroutine, of which there are at least 25. Maybe we need a standardised way to run a goroutine i.e.
```
go safeGoroutine(func() {
// do stuff
})

func safeGoroutine(f func()) {
defer func() {
if r := recover(); r != nil {
termbox.Close()
panic(r)
}
}()
f()
}
```

Luckily termbox is defined globally so we can do this from anywhere. I might actually chuck a 'good first issue' label on this one

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.