summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-03-22 09:52:27 +0100
committerRobin Jarry <robin@jarry.cc>2022-03-23 20:56:09 +0100
commitae83373fa63883f03bd5580ad3937d1e5fa428ed (patch)
tree12e7bae80292088f7dfed45279fa3bce225743bf /commands
parentfeecc09b73e2c904be42f271e0c10574b98a95ea (diff)
downloadaerc-ae83373fa63883f03bd5580ad3937d1e5fa428ed.zip
logging: added a log on panic
Since panics still regularly "destroy" the terminal, it is hard to get a stack trace for panics you do not anticipate. This commit adds a panic handler that automatically creates a logfile inside the current working directory. It has to be added to every goroutine that is started and will repair the terminal on a panic. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/compose.go7
-rw-r--r--commands/account/recover.go7
-rw-r--r--commands/compose/postpone.go3
-rw-r--r--commands/compose/send.go5
-rw-r--r--commands/exec.go3
-rw-r--r--commands/msg/archive.go3
-rw-r--r--commands/msg/pipe.go5
-rw-r--r--commands/msg/read.go3
-rw-r--r--commands/msgview/open.go3
-rw-r--r--commands/msgview/save.go3
-rw-r--r--commands/util.go3
11 files changed, 43 insertions, 2 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go
index 1a62d0a..4884b11 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -5,6 +5,7 @@ import (
"regexp"
"strings"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~sircmpwn/getopt"
@@ -52,7 +53,11 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
}
tab.Content.Invalidate()
})
- go composer.AppendContents(strings.NewReader(body))
+ go func() {
+ defer logging.PanicHandler()
+
+ composer.AppendContents(strings.NewReader(body))
+ }()
return nil
}
diff --git a/commands/account/recover.go b/commands/account/recover.go
index 8158af6..165e88e 100644
--- a/commands/account/recover.go
+++ b/commands/account/recover.go
@@ -8,6 +8,7 @@ import (
"path/filepath"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~sircmpwn/getopt"
@@ -111,7 +112,11 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error {
tab.Name = subject
tab.Content.Invalidate()
})
- go composer.AppendContents(bytes.NewReader(data))
+ go func() {
+ defer logging.PanicHandler()
+
+ composer.AppendContents(bytes.NewReader(data))
+ }()
// remove file if force flag is set
if force {
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index 9462a9c..a4ac5c6 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -8,6 +8,7 @@ import (
"github.com/miolini/datacounter"
"github.com/pkg/errors"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -66,6 +67,8 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
// run this as a goroutine so we can make other progress. The message
// will be saved once the directory is created.
go func() {
+ defer logging.PanicHandler()
+
errStr := <-errChan
if errStr != "" {
aerc.PushError(errStr)
diff --git a/commands/compose/send.go b/commands/compose/send.go
index dbdb94f..574e872 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -16,6 +16,7 @@ import (
"github.com/pkg/errors"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -100,6 +101,8 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
failCh := make(chan error)
//writer
go func() {
+ defer logging.PanicHandler()
+
var sender io.WriteCloser
switch ctx.scheme {
case "smtp":
@@ -131,6 +134,8 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
//cleanup + copy to sent
go func() {
+ defer logging.PanicHandler()
+
err = <-failCh
if err != nil {
aerc.PushError(strings.ReplaceAll(err.Error(), "\n", " "))
diff --git a/commands/exec.go b/commands/exec.go
index 317bf07..bce62bd 100644
--- a/commands/exec.go
+++ b/commands/exec.go
@@ -7,6 +7,7 @@ import (
"os/exec"
"time"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/widgets"
)
@@ -45,6 +46,8 @@ func (ExecCmd) Execute(aerc *widgets.Aerc, args []string) error {
cmd.Env = env
go func() {
+ defer logging.PanicHandler()
+
err := cmd.Run()
if err != nil {
aerc.PushError(err.Error())
diff --git a/commands/msg/archive.go b/commands/msg/archive.go
index 8f832e5..ebe63ff 100644
--- a/commands/msg/archive.go
+++ b/commands/msg/archive.go
@@ -8,6 +8,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -94,6 +95,8 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error {
}
// we need to do that in the background, else we block the main thread
go func() {
+ defer logging.PanicHandler()
+
wg.Wait()
if success {
aerc.PushStatus("Messages archived.", 10*time.Second)
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index 5d8a042..06f2a4d 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -9,6 +9,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -89,6 +90,8 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
return
}
go func() {
+ defer logging.PanicHandler()
+
defer pipe.Close()
io.Copy(pipe, reader)
}()
@@ -146,6 +149,8 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
})
go func() {
+ defer logging.PanicHandler()
+
select {
case <-done:
break
diff --git a/commands/msg/read.go b/commands/msg/read.go
index d2484d4..4f8880a 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -8,6 +8,7 @@ import (
"git.sr.ht/~sircmpwn/getopt"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -169,6 +170,8 @@ func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error {
// We need to do flagging in the background, else we block the main thread
go func() {
+ defer logging.PanicHandler()
+
wg.Wait()
if success {
aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 5b19912..d8a4de0 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -9,6 +9,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/widgets"
)
@@ -66,6 +67,8 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
return
}
go func() {
+ defer logging.PanicHandler()
+
err := xdg.Wait()
if err != nil {
aerc.PushError(err.Error())
diff --git a/commands/msgview/save.go b/commands/msgview/save.go
index 26a6bf2..48add98 100644
--- a/commands/msgview/save.go
+++ b/commands/msgview/save.go
@@ -13,6 +13,7 @@ import (
"github.com/mitchellh/go-homedir"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
)
@@ -126,6 +127,8 @@ func (Save) Execute(aerc *widgets.Aerc, args []string) error {
// we need to wait for the callback prior to displaying a result
go func() {
+ defer logging.PanicHandler()
+
err := <-ch
if err != nil {
aerc.PushError(fmt.Sprintf("Save failed: %v", err))
diff --git a/commands/util.go b/commands/util.go
index 92b851a..1c4a8c9 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -13,6 +13,7 @@ import (
"github.com/lithammer/fuzzysearch/fuzzy"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
"github.com/gdamore/tcell/v2"
@@ -51,6 +52,8 @@ func QuickTerm(aerc *widgets.Aerc, args []string, stdin io.Reader) (*widgets.Ter
status := make(chan error, 1)
go func() {
+ defer logging.PanicHandler()
+
_, err := io.Copy(pipe, stdin)
defer pipe.Close()
status <- err