diff options
author | Robin Jarry <robin@jarry.cc> | 2023-01-06 22:49:26 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-06 23:51:58 +0100 |
commit | 915b869e3fc6377be114c033763987de612c443c (patch) | |
tree | 95a2165a06cbda9ad0d092ac1b3816f50daa52c1 | |
parent | 175c1c822084d0f42892729c8e095397bd830966 (diff) | |
download | aerc-915b869e3fc6377be114c033763987de612c443c.tar.gz |
lint: add missing panic handlers in goroutines
These issues were all reported by the new custom analyzer introduced in
previous commit.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
-rw-r--r-- | commands/account/export-mbox.go | 1 | ||||
-rw-r--r-- | commands/account/import-mbox.go | 1 | ||||
-rw-r--r-- | commands/msg/pipe.go | 1 | ||||
-rw-r--r-- | commands/msg/unsubscribe.go | 1 | ||||
-rw-r--r-- | commands/msgview/open-link.go | 2 | ||||
-rw-r--r-- | commands/msgview/open.go | 2 | ||||
-rw-r--r-- | lib/ui/ui.go | 2 | ||||
-rw-r--r-- | widgets/account-wizard.go | 2 | ||||
-rw-r--r-- | widgets/account.go | 1 | ||||
-rw-r--r-- | worker/imap/cache.go | 1 | ||||
-rw-r--r-- | worker/imap/connect.go | 2 | ||||
-rw-r--r-- | worker/imap/observer.go | 2 | ||||
-rw-r--r-- | worker/maildir/search.go | 1 | ||||
-rw-r--r-- | worker/maildir/worker.go | 4 | ||||
-rw-r--r-- | worker/notmuch/worker.go | 2 | ||||
-rw-r--r-- | worker/types/worker.go | 1 |
16 files changed, 26 insertions, 0 deletions
diff --git a/commands/account/export-mbox.go b/commands/account/export-mbox.go index cbb56e61..5051906c 100644 --- a/commands/account/export-mbox.go +++ b/commands/account/export-mbox.go @@ -53,6 +53,7 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { aerc.PushStatus("Exporting to "+filename, 10*time.Second) go func() { + defer log.PanicHandler() file, err := os.Create(filename) if err != nil { log.Errorf("failed to create file: %v", err) diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go index c1ee5936..5d6a0a0c 100644 --- a/commands/account/import-mbox.go +++ b/commands/account/import-mbox.go @@ -53,6 +53,7 @@ func (ImportMbox) Execute(aerc *widgets.Aerc, args []string) error { } importFolder := func() { + defer log.PanicHandler() statusInfo := fmt.Sprintln("Importing", filename, "to folder", folder) aerc.PushStatus(statusInfo, 10*time.Second) log.Debugf(statusInfo) diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go index 878fd18c..fc1ac8f8 100644 --- a/commands/msg/pipe.go +++ b/commands/msg/pipe.go @@ -236,6 +236,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error { func newMessagesReader(messages []*types.FullMessage, useMbox bool) io.Reader { pr, pw := io.Pipe() go func() { + defer log.PanicHandler() defer pw.Close() for _, msg := range messages { var err error diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go index 66797660..37ed707f 100644 --- a/commands/msg/unsubscribe.go +++ b/commands/msg/unsubscribe.go @@ -183,6 +183,7 @@ func unsubscribeHTTP(aerc *widgets.Aerc, u *url.URL) error { switch option { case "Yes": go func() { + defer log.PanicHandler() if err := lib.XDGOpen(u.String()); err != nil { aerc.PushError("Unsubscribe:" + err.Error()) } diff --git a/commands/msgview/open-link.go b/commands/msgview/open-link.go index d19dfae0..257a2fdc 100644 --- a/commands/msgview/open-link.go +++ b/commands/msgview/open-link.go @@ -5,6 +5,7 @@ import ( "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -33,6 +34,7 @@ func (OpenLink) Execute(aerc *widgets.Aerc, args []string) error { return errors.New("Usage: open-link <url>") } go func() { + defer log.PanicHandler() if err := lib.XDGOpen(args[1]); err != nil { aerc.PushError("open-link: " + err.Error()) } diff --git a/commands/msgview/open.go b/commands/msgview/open.go index 1b9efb38..0380b51a 100644 --- a/commands/msgview/open.go +++ b/commands/msgview/open.go @@ -7,6 +7,7 @@ import ( "os" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/widgets" ) @@ -57,6 +58,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error { } go func() { + defer log.PanicHandler() err = lib.XDGOpenMime(tmpFile.Name(), mimeType, args[1:]) if err != nil { aerc.PushError("open: " + err.Error()) diff --git a/lib/ui/ui.go b/lib/ui/ui.go index bbaa3a29..05a44e4a 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -3,6 +3,7 @@ package ui import ( "sync/atomic" + "git.sr.ht/~rjarry/aerc/log" "github.com/gdamore/tcell/v2" ) @@ -122,6 +123,7 @@ func (state *UI) EnableMouse() { func (state *UI) ChannelEvents() { go func() { + defer log.PanicHandler() for { MsgChannel <- state.screen.PollEvent() } diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 4b948a30..c1d237ef 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -20,6 +20,7 @@ import ( "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/log" ) const ( @@ -144,6 +145,7 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard { once.Do(func() { // debounce to ensure pasted passwords are pasted completely go func() { + defer log.PanicHandler() for !time.Now().After(lastChange.Add(10 * time.Millisecond)) { <-time.After(10 * time.Millisecond) } diff --git a/widgets/account.go b/widgets/account.go index 73ee32d0..c2b8b8e9 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -463,6 +463,7 @@ func (acct *AccountView) checkMailOnStartup() { func (acct *AccountView) CheckMailTimer(d time.Duration) { acct.ticker = time.NewTicker(d) go func() { + defer log.PanicHandler() for range acct.ticker.C { if !acct.state.Connected() { continue diff --git a/worker/imap/cache.go b/worker/imap/cache.go index b8673ae7..352ef313 100644 --- a/worker/imap/cache.go +++ b/worker/imap/cache.go @@ -145,6 +145,7 @@ func cacheDir() (string, error) { // cleanCache removes stale entries from the selected mailbox cachedb func (w *IMAPWorker) cleanCache(path string) { + defer log.PanicHandler() start := time.Now() var scanned, removed int iter := w.cache.NewIterator(nil, nil) diff --git a/worker/imap/connect.go b/worker/imap/connect.go index d6c946db..5be916e7 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -111,6 +111,7 @@ func newTCPConn(addr string, timeout time.Duration) (*net.TCPConn, error) { done := make(chan tcpConn) go func() { + defer log.PanicHandler() addr, err := net.ResolveTCPAddr("tcp", addr) if err != nil { done <- tcpConn{nil, err} @@ -129,6 +130,7 @@ func newTCPConn(addr string, timeout time.Duration) (*net.TCPConn, error) { select { case <-time.After(timeout): go func() { + defer log.PanicHandler() if tcpResult := <-done; tcpResult.conn != nil { tcpResult.conn.Close() } diff --git a/worker/imap/observer.go b/worker/imap/observer.go index 2cfe8bd9..9ad311dd 100644 --- a/worker/imap/observer.go +++ b/worker/imap/observer.go @@ -76,6 +76,7 @@ func (o *observer) Start() { return } go func() { + defer log.PanicHandler() select { case <-o.client.LoggedOut(): o.log("<-logout") @@ -129,6 +130,7 @@ func (o *observer) DelayedReconnect() error { } go func() { + defer log.PanicHandler() <-time.After(wait) o.emit(reterr.Error()) }() diff --git a/worker/maildir/search.go b/worker/maildir/search.go index e70282e2..c667d48f 100644 --- a/worker/maildir/search.go +++ b/worker/maildir/search.go @@ -120,6 +120,7 @@ func (w *Worker) search(criteria *searchCriteria) ([]uint32, error) { limit <- struct{}{} wg.Add(1) go func(key uint32) { + defer log.PanicHandler() defer wg.Done() success, err := w.searchKey(key, criteria, requiredParts) if err != nil { diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 54069538..a8ed0b50 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -458,6 +458,7 @@ func (w *Worker) sort(uids []uint32, criteria []*types.SortCriterion) ([]uint32, limit <- struct{}{} wg.Add(1) go func(uid uint32) { + defer log.PanicHandler() defer wg.Done() info, err := w.msgHeadersFromUid(uid) if err != nil { @@ -528,6 +529,7 @@ func (w *Worker) threads(uids []uint32, criteria []*types.SortCriterion) ([]*typ limit <- struct{}{} wg.Add(1) go func(uid uint32) { + defer log.PanicHandler() defer wg.Done() info, err := w.msgHeadersFromUid(uid) if err != nil { @@ -835,6 +837,7 @@ func (w *Worker) msgHeadersFromUid(uid uint32) (*models.MessageInfo, error) { } func (w *Worker) handleCheckMail(msg *types.CheckMail) { + defer log.PanicHandler() if msg.Command == "" { w.err(msg, fmt.Errorf("checkmail: no command specified")) return @@ -844,6 +847,7 @@ func (w *Worker) handleCheckMail(msg *types.CheckMail) { cmd := exec.CommandContext(ctx, "sh", "-c", msg.Command) ch := make(chan error) go func() { + defer log.PanicHandler() err := cmd.Run() ch <- err }() diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 6d8e46d2..3b4bd5dc 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -688,6 +688,7 @@ func (w *worker) sort(uids []uint32, } func (w *worker) handleCheckMail(msg *types.CheckMail) { + defer log.PanicHandler() if msg.Command == "" { w.err(msg, fmt.Errorf("checkmail: no command specified")) return @@ -697,6 +698,7 @@ func (w *worker) handleCheckMail(msg *types.CheckMail) { cmd := exec.CommandContext(ctx, "sh", "-c", msg.Command) ch := make(chan error) go func() { + defer log.PanicHandler() err := cmd.Run() ch <- err }() diff --git a/worker/types/worker.go b/worker/types/worker.go index bd3553bc..a9056c0a 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -64,6 +64,7 @@ func (worker *Worker) queue(msg WorkerMessage) { // Start processing the action queue and write all messages to the Actions // channel, one by one. Stop when the action queue is empty. func (worker *Worker) processQueue() { + defer log.PanicHandler() for { worker.Lock() e := worker.actionQueue.Front() |