aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2021-02-11 21:02:46 +0100
committerReto Brunner <reto@labrat.space>2021-02-11 21:02:46 +0100
commitc06a2e61fc32051d429dbbaf4dc3cc0019f4a69c (patch)
treef340e063d6daf73eeaa05bb9ad2233dae657d0a8
parent8ecf0b73f41f9319f9d89d61f8d4619aa4e69758 (diff)
downloadaerc-c06a2e61fc32051d429dbbaf4dc3cc0019f4a69c.tar.gz
aerc: try to recover from a panic
As of now we crash fairly often. The problem is that we didn't run the cleanup routine of the ui in this case, leaving the pty in a bad state. Instead, recover from a panic and at least try to run the ui deinit.
-rw-r--r--aerc.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/aerc.go b/aerc.go
index 17b3c576..33acb434 100644
--- a/aerc.go
+++ b/aerc.go
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
+ "runtime/debug"
"sort"
"time"
@@ -153,6 +154,8 @@ func main() {
ui *libui.UI
)
+ defer PanicTermFix(ui) // recover upon panic and try restoring the pty
+
aerc = widgets.NewAerc(conf, logger, func(cmd []string) error {
return execCommand(aerc, ui, cmd)
}, func(cmd string) []string {
@@ -198,3 +201,19 @@ func main() {
}
aerc.CloseBackends()
}
+
+//FatalTermFix prints the stacktrace upon panic and tries to recover the term
+// not doing that leaves the terminal in a broken state
+func PanicTermFix(ui *libui.UI) {
+ var err interface{}
+ if err = recover(); err == nil {
+ return
+ }
+ debug.PrintStack()
+ if ui != nil {
+ ui.Close()
+ }
+ fmt.Fprintf(os.Stderr, "aerc crashed: %v\n", err)
+ os.Exit(1)
+
+}