diff options
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/configure.go | 18 | ||||
-rw-r--r-- | worker/imap/fetch.go | 4 | ||||
-rw-r--r-- | worker/imap/worker.go | 2 | ||||
-rw-r--r-- | worker/lib/parse.go | 26 | ||||
-rw-r--r-- | worker/maildir/container.go | 6 | ||||
-rw-r--r-- | worker/maildir/message.go | 4 | ||||
-rw-r--r-- | worker/maildir/worker.go | 80 | ||||
-rw-r--r-- | worker/mbox/io.go | 3 | ||||
-rw-r--r-- | worker/mbox/models.go | 2 | ||||
-rw-r--r-- | worker/mbox/worker.go | 27 | ||||
-rw-r--r-- | worker/notmuch/lib/database.go | 5 | ||||
-rw-r--r-- | worker/notmuch/message.go | 2 | ||||
-rw-r--r-- | worker/notmuch/worker.go | 67 | ||||
-rw-r--r-- | worker/types/thread.go | 4 |
14 files changed, 127 insertions, 123 deletions
diff --git a/worker/imap/configure.go b/worker/imap/configure.go index f5151880..691e0d76 100644 --- a/worker/imap/configure.go +++ b/worker/imap/configure.go @@ -65,7 +65,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := time.ParseDuration(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid idle-timeout value %v: %v", + "invalid idle-timeout value %v: %w", value, err) } w.config.idle_timeout = val @@ -73,7 +73,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := time.ParseDuration(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid idle-debounce value %v: %v", + "invalid idle-debounce value %v: %w", value, err) } w.config.idle_debounce = val @@ -81,7 +81,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := time.ParseDuration(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid reconnect-maxwait value %v: %v", + "invalid reconnect-maxwait value %v: %w", value, err) } w.config.reconnect_maxwait = val @@ -89,7 +89,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := time.ParseDuration(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid connection-timeout value %v: %v", + "invalid connection-timeout value %v: %w", value, err) } w.config.connection_timeout = val @@ -97,7 +97,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := time.ParseDuration(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid keepalive-period value %v: %v", + "invalid keepalive-period value %v: %w", value, err) } w.config.keepalive_period = val @@ -105,7 +105,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := strconv.Atoi(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid keepalive-probes value %v: %v", + "invalid keepalive-probes value %v: %w", value, err) } w.config.keepalive_probes = val @@ -113,7 +113,7 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { val, err := time.ParseDuration(value) if err != nil || val < 0 { return fmt.Errorf( - "invalid keepalive-interval value %v: %v", + "invalid keepalive-interval value %v: %w", value, err) } w.config.keepalive_interval = int(val.Seconds()) @@ -123,13 +123,13 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { // Return an error here because the user tried to set header // caching, and we want them to know they didn't set it right - // one way or the other - return fmt.Errorf("invalid cache-headers value %v: %v", value, err) + return fmt.Errorf("invalid cache-headers value %v: %w", value, err) } w.config.cacheEnabled = cache case "cache-max-age": val, err := time.ParseDuration(value) if err != nil || val < 0 { - return fmt.Errorf("invalid cache-max-age value %v: %v", value, err) + return fmt.Errorf("invalid cache-max-age value %v: %w", value, err) } w.config.cacheMaxAge = val } diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index 41269cbf..f21c6e91 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -118,13 +118,13 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart( } h, err := textproto.ReadHeader(bufio.NewReader(body)) if err != nil { - return fmt.Errorf("failed to read part header: %v", err) + return fmt.Errorf("failed to read part header: %w", err) } part, err := message.New(message.Header{Header: h}, _msg.GetBody(&partBodySection)) if err != nil { - return fmt.Errorf("failed to create message reader: %v", err) + return fmt.Errorf("failed to create message reader: %w", err) } imapw.worker.PostMessage(&types.MessageBodyPart{ diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 40debe64..6b6c9261 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -282,7 +282,7 @@ func (w *IMAPWorker) Run() { case msg := <-w.worker.Actions: msg = w.worker.ProcessAction(msg) - if err := w.handleMessage(msg); err == errUnsupported { + if err := w.handleMessage(msg); errors.Is(err, errUnsupported) { w.worker.PostMessage(&types.Unsupported{ Message: types.RespondTo(msg), }, nil) diff --git a/worker/lib/parse.go b/worker/lib/parse.go index d92eeda7..ad5e0a8b 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -104,7 +104,7 @@ func ParseEntityStructure(e *message.Entity) (*models.BodyStructure, error) { if cd := e.Header.Get("content-disposition"); cd != "" { contentDisposition, cdParams, err := e.Header.ContentDisposition() if err != nil { - return nil, fmt.Errorf("could not parse content disposition: %v", err) + return nil, fmt.Errorf("could not parse content disposition: %w", err) } body.Disposition = contentDisposition body.DispositionParams = cdParams @@ -113,7 +113,7 @@ func ParseEntityStructure(e *message.Entity) (*models.BodyStructure, error) { if mpr := e.MultipartReader(); mpr != nil { for { part, err := mpr.NextPart() - if err == io.EOF { + if errors.Is(err, io.EOF) { return &body, nil } else if err != nil { return nil, err @@ -133,27 +133,27 @@ var DateParseError = errors.New("date parsing failed") func parseEnvelope(h *mail.Header) (*models.Envelope, error) { from, err := parseAddressList(h, "from") if err != nil { - return nil, fmt.Errorf("could not read from address: %v", err) + return nil, fmt.Errorf("could not read from address: %w", err) } to, err := parseAddressList(h, "to") if err != nil { - return nil, fmt.Errorf("could not read to address: %v", err) + return nil, fmt.Errorf("could not read to address: %w", err) } cc, err := parseAddressList(h, "cc") if err != nil { - return nil, fmt.Errorf("could not read cc address: %v", err) + return nil, fmt.Errorf("could not read cc address: %w", err) } bcc, err := parseAddressList(h, "bcc") if err != nil { - return nil, fmt.Errorf("could not read bcc address: %v", err) + return nil, fmt.Errorf("could not read bcc address: %w", err) } replyTo, err := parseAddressList(h, "reply-to") if err != nil { - return nil, fmt.Errorf("could not read reply-to address: %v", err) + return nil, fmt.Errorf("could not read reply-to address: %w", err) } subj, err := h.Subject() if err != nil { - return nil, fmt.Errorf("could not read subject: %v", err) + return nil, fmt.Errorf("could not read subject: %w", err) } msgID, err := h.MessageID() if err != nil { @@ -167,7 +167,7 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) { if err != nil { // still return a valid struct plus a sentinel date parsing error // if only the date parsing failed - err = fmt.Errorf("%w: %v", DateParseError, err) + err = fmt.Errorf("%v: %w", DateParseError, err) } return &models.Envelope{ Date: date, @@ -217,7 +217,7 @@ func parseDate(h *mail.Header) (time.Time, error) { func parseReceivedHeader(h *mail.Header) (time.Time, error) { guess, err := h.Text("received") if err != nil { - return time.Time{}, fmt.Errorf("received header not parseable: %v", + return time.Time{}, fmt.Errorf("received header not parseable: %w", err) } return time.Parse(time.RFC1123Z, dateRe.FindString(guess)) @@ -254,18 +254,18 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) { defer r.Close() msg, err := message.Read(r) if err != nil { - return nil, fmt.Errorf("could not read message: %v", err) + return nil, fmt.Errorf("could not read message: %w", err) } bs, err := ParseEntityStructure(msg) if errors.As(err, new(message.UnknownEncodingError)) { parseErr = err } else if err != nil { - return nil, fmt.Errorf("could not get structure: %v", err) + return nil, fmt.Errorf("could not get structure: %w", err) } h := &mail.Header{Header: msg.Header} env, err := parseEnvelope(h) if err != nil && !errors.Is(err, DateParseError) { - return nil, fmt.Errorf("could not parse envelope: %v", err) + return nil, fmt.Errorf("could not parse envelope: %w", err) // if only the date parsing failed we still get the rest of the // envelop structure in a valid state. // Date parsing errors are fairly common and it's better to be diff --git a/worker/maildir/container.go b/worker/maildir/container.go index 35125775..a8ac1aca 100644 --- a/worker/maildir/container.go +++ b/worker/maildir/container.go @@ -50,7 +50,7 @@ func (c *Container) ListFolders() ([]string, error) { } err := filepath.Walk(c.dir, func(path string, info os.FileInfo, err error) error { if err != nil { - return fmt.Errorf("Invalid path '%s': error: %v", path, err) + return fmt.Errorf("Invalid path '%s': error: %w", path, err) } if !info.IsDir() { return nil @@ -144,7 +144,7 @@ func (c *Container) ClearRecentFlag(uid uint32) { func (c *Container) UIDs(d maildir.Dir) ([]uint32, error) { keys, err := d.Keys() if err != nil { - return nil, fmt.Errorf("could not get keys for %s: %v", d, err) + return nil, fmt.Errorf("could not get keys for %s: %w", d, err) } sort.Strings(keys) var uids []uint32 @@ -189,7 +189,7 @@ func (c *Container) CopyAll( ) error { for _, uid := range uids { if err := c.copyMessage(dest, src, uid); err != nil { - return fmt.Errorf("could not copy message %d: %v", uid, err) + return fmt.Errorf("could not copy message %d: %w", uid, err) } } return nil diff --git a/worker/maildir/message.go b/worker/maildir/message.go index b73e0832..81573c50 100644 --- a/worker/maildir/message.go +++ b/worker/maildir/message.go @@ -46,7 +46,7 @@ func (m Message) SetFlags(flags []maildir.Flag) error { func (m Message) SetOneFlag(flag maildir.Flag, enable bool) error { flags, err := m.Flags() if err != nil { - return fmt.Errorf("could not read previous flags: %v", err) + return fmt.Errorf("could not read previous flags: %w", err) } if enable { flags = append(flags, flag) @@ -87,7 +87,7 @@ func (m Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) { defer f.Close() msg, err := message.Read(f) if err != nil { - return nil, fmt.Errorf("could not read message: %v", err) + return nil, fmt.Errorf("could not read message: %w", err) } return lib.FetchEntityPartReader(msg, requestedParts) } diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index a770b2f4..9f9fee9a 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -46,7 +46,7 @@ type Worker struct { func NewWorker(worker *types.Worker) (types.Backend, error) { watch, err := fsnotify.NewWatcher() if err != nil { - return nil, fmt.Errorf("could not create file system watcher: %v", err) + return nil, fmt.Errorf("could not create file system watcher: %w", err) } return &Worker{worker: worker, watcher: watch}, nil } @@ -55,7 +55,7 @@ func NewWorker(worker *types.Worker) (types.Backend, error) { func NewMaildirppWorker(worker *types.Worker) (types.Backend, error) { watch, err := fsnotify.NewWatcher() if err != nil { - return nil, fmt.Errorf("could not create file system watcher: %v", err) + return nil, fmt.Errorf("could not create file system watcher: %w", err) } return &Worker{worker: worker, watcher: watch, maildirpp: true}, nil } @@ -112,18 +112,18 @@ func (w *Worker) handleFSEvent(ev fsnotify.Event) { } err := w.c.SyncNewMail(*w.selected) if err != nil { - logging.Errorf("could not move new to cur : %v", err) + logging.Errorf("could not move new to cur : %w", err) return } uids, err := w.c.UIDs(*w.selected) if err != nil { - logging.Errorf("could not scan UIDs: %v", err) + logging.Errorf("could not scan UIDs: %w", err) return } sortedUids, err := w.sort(uids, w.currentSortCriteria) if err != nil { - logging.Errorf("error sorting directory: %v", err) + logging.Errorf("error sorting directory: %w", err) return } w.worker.PostMessage(&types.DirectoryContents{ @@ -204,18 +204,18 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { for _, v := range files { key, flags, err := splitMaildirFile(v) if err != nil { - logging.Errorf("%q: error parsing flags (%q): %v", v, key, err) + logging.Errorf("%q: error parsing flags (%q): %w", v, key, err) continue } keyFlags[key] = flags } } else { - logging.Infof("disabled flags cache: %q: %v", dir, err) + logging.Infof("disabled flags cache: %q: %w", dir, err) } uids, err := w.c.UIDs(dir) if err != nil { - logging.Errorf("could not get uids: %v", err) + logging.Errorf("could not get uids: %w", err) return dirInfo } @@ -223,7 +223,7 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { for _, uid := range uids { message, err := w.c.Message(dir, uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) continue } var flags []maildir.Flag @@ -234,14 +234,14 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { logging.Debugf("message (key=%q uid=%d) not found in map cache", message.key, message.uid) flags, err = message.Flags() if err != nil { - logging.Errorf("could not get flags: %v", err) + logging.Errorf("could not get flags: %w", err) continue } } } else { flags, err = message.Flags() if err != nil { - logging.Errorf("could not get flags: %v", err) + logging.Errorf("could not get flags: %w", err) continue } } @@ -306,14 +306,14 @@ func (w *Worker) handleMessage(msg types.WorkerMessage) error { func (w *Worker) handleConfigure(msg *types.Configure) error { u, err := url.Parse(msg.Config.Source) if err != nil { - logging.Errorf("error configuring maildir worker: %v", err) + logging.Errorf("error configuring maildir worker: %w", err) return err } dir := u.Path if u.Host == "~" { home, err := os.UserHomeDir() if err != nil { - return fmt.Errorf("could not resolve home directory: %v", err) + return fmt.Errorf("could not resolve home directory: %w", err) } dir = filepath.Join(home, u.Path) } @@ -343,7 +343,7 @@ func (w *Worker) handleListDirectories(msg *types.ListDirectories) error { } dirs, err := w.c.ListFolders() if err != nil { - logging.Errorf("failed listing directories: %v", err) + logging.Errorf("failed listing directories: %w", err) return err } for _, name := range dirs { @@ -375,11 +375,11 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error { if w.selected != nil { prevDir := filepath.Join(string(*w.selected), "new") if err := w.watcher.Remove(prevDir); err != nil { - return fmt.Errorf("could not unwatch previous directory: %v", err) + return fmt.Errorf("could not unwatch previous directory: %w", err) } prevDir = filepath.Join(string(*w.selected), "cur") if err := w.watcher.Remove(prevDir); err != nil { - return fmt.Errorf("could not unwatch previous directory: %v", err) + return fmt.Errorf("could not unwatch previous directory: %w", err) } } @@ -389,15 +389,15 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error { // add watch paths newDir := filepath.Join(string(*w.selected), "new") if err := w.watcher.Add(newDir); err != nil { - return fmt.Errorf("could not add watch to directory: %v", err) + return fmt.Errorf("could not add watch to directory: %w", err) } newDir = filepath.Join(string(*w.selected), "cur") if err := w.watcher.Add(newDir); err != nil { - return fmt.Errorf("could not add watch to directory: %v", err) + return fmt.Errorf("could not add watch to directory: %w", err) } if err := dir.Clean(); err != nil { - return fmt.Errorf("could not clean directory: %v", err) + return fmt.Errorf("could not clean directory: %w", err) } info := &types.DirectoryInfo{ @@ -426,13 +426,13 @@ func (w *Worker) handleFetchDirectoryContents( } else { uids, err = w.c.UIDs(*w.selected) if err != nil { - logging.Errorf("failed scanning uids: %v", err) + logging.Errorf("failed scanning uids: %w", err) return err } } sortedUids, err := w.sort(uids, msg.SortCriteria) if err != nil { - logging.Errorf("failed sorting directory: %v", err) + logging.Errorf("failed sorting directory: %w", err) return err } w.currentSortCriteria = msg.SortCriteria @@ -451,14 +451,14 @@ func (w *Worker) sort(uids []uint32, criteria []*types.SortCriterion) ([]uint32, for _, uid := range uids { info, err := w.msgInfoFromUid(uid) if err != nil { - logging.Errorf("could not get message info: %v", err) + logging.Errorf("could not get message info: %w", err) continue } msgInfos = append(msgInfos, info) } sortedUids, err := lib.Sort(msgInfos, criteria) if err != nil { - logging.Errorf("could not sort the messages: %v", err) + logging.Errorf("could not sort the messages: %w", err) return nil, err } return sortedUids, nil @@ -467,7 +467,7 @@ func (w *Worker) sort(uids []uint32, criteria []*types.SortCriterion) ([]uint32, func (w *Worker) handleCreateDirectory(msg *types.CreateDirectory) error { dir := w.c.Dir(msg.Directory) if err := dir.Init(); err != nil { - logging.Errorf("could not create directory %s: %v", + logging.Errorf("could not create directory %s: %w", msg.Directory, err) return err } @@ -477,7 +477,7 @@ func (w *Worker) handleCreateDirectory(msg *types.CreateDirectory) error { func (w *Worker) handleRemoveDirectory(msg *types.RemoveDirectory) error { dir := w.c.Dir(msg.Directory) if err := os.RemoveAll(string(dir)); err != nil { - logging.Errorf("could not remove directory %s: %v", + logging.Errorf("could not remove directory %s: %w", msg.Directory, err) return err } @@ -490,7 +490,7 @@ func (w *Worker) handleFetchMessageHeaders( for _, uid := range msg.Uids { info, err := w.msgInfoFromUid(uid) if err != nil { - logging.Errorf("could not get message info: %v", err) + logging.Errorf("could not get message info: %w", err) w.err(msg, err) continue } @@ -509,13 +509,13 @@ func (w *Worker) handleFetchMessageBodyPart( // get reader m, err := w.c.Message(*w.selected, msg.Uid) if err != nil { - logging.Errorf("could not get message %d: %v", msg.Uid, err) + logging.Errorf("could not get message %d: %w", msg.Uid, err) return err } r, err := m.NewBodyPartReader(msg.Part) if err != nil { logging.Errorf( - "could not get body part reader for message=%d, parts=%#v: %v", + "could not get body part reader for message=%d, parts=%#v: %w", msg.Uid, msg.Part, err) return err } @@ -534,12 +534,12 @@ func (w *Worker) handleFetchFullMessages(msg *types.FetchFullMessages) error { for _, uid := range msg.Uids { m, err := w.c.Message(*w.selected, uid) if err != nil { - logging.Errorf("could not get message %d: %v", uid, err) + logging.Errorf("could not get message %d: %w", uid, err) return err } r, err := m.NewReader() if err != nil { - logging.Errorf("could not get message reader: %v", err) + logging.Errorf("could not get message reader: %w", err) return err } defer r.Close() @@ -570,7 +570,7 @@ func (w *Worker) handleDeleteMessages(msg *types.DeleteMessages) error { }, nil) } if err != nil { - logging.Errorf("failed removing messages: %v", err) + logging.Errorf("failed removing messages: %w", err) return err } return nil @@ -580,18 +580,18 @@ func (w *Worker) handleAnsweredMessages(msg *types.AnsweredMessages) error { for _, uid := range msg.Uids { m, err := w.c.Message(*w.selected, uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) w.err(msg, err) continue } if err := m.MarkReplied(msg.Answered); err != nil { - logging.Errorf("could not mark message as answered: %v", err) + logging.Errorf("could not mark message as answered: %w", err) w.err(msg, err) continue } info, err := m.MessageInfo() if err != nil { - logging.Errorf("could not get message info: %v", err) + logging.Errorf("could not get message info: %w", err) w.err(msg, err) continue } @@ -612,19 +612,19 @@ func (w *Worker) handleFlagMessages(msg *types.FlagMessages) error { for _, uid := range msg.Uids { m, err := w.c.Message(*w.selected, uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) w.err(msg, err) continue } flag := flagToMaildir[msg.Flag] if err := m.SetOneFlag(flag, msg.Enable); err != nil { - logging.Errorf("could change flag %v to %v on message: %v", flag, msg.Enable, err) + logging.Errorf("could change flag %v to %v on message: %w", flag, msg.Enable, err) w.err(msg, err) continue } info, err := m.MessageInfo() if err != nil { - logging.Errorf("could not get message info: %v", err) + logging.Errorf("could not get message info: %w", err) w.err(msg, err) continue } @@ -661,12 +661,12 @@ func (w *Worker) handleAppendMessage(msg *types.AppendMessage) error { dest := w.c.Dir(msg.Destination) _, writer, err := dest.Create(translateFlags(msg.Flags)) if err != nil { - logging.Errorf("could not create message at %s: %v", msg.Destination, err) + logging.Errorf("could not create message at %s: %w", msg.Destination, err) return err } defer writer.Close() if _, err := io.Copy(writer, msg.Reader); err != nil { - logging.Errorf("could not write message to destination: %v", err) + logging.Errorf("could not write message to destination: %w", err) return err } w.worker.PostMessage(&types.Done{ @@ -729,7 +729,7 @@ func (w *Worker) handleCheckMail(msg *types.CheckMail) { w.err(msg, fmt.Errorf("checkmail: timed out")) case err := <-ch: if err != nil { - w.err(msg, fmt.Errorf("checkmail: error running command: %v", err)) + w.err(msg, fmt.Errorf("checkmail: error running command: %w", err)) } else { w.done(msg) } diff --git a/worker/mbox/io.go b/worker/mbox/io.go index 38469160..67290482 100644 --- a/worker/mbox/io.go +++ b/worker/mbox/io.go @@ -1,6 +1,7 @@ package mboxer import ( + "errors" "io" "io/ioutil" "time" @@ -16,7 +17,7 @@ func Read(r io.Reader) ([]lib.RawMessage, error) { messages := make([]lib.RawMessage, 0) for { msg, err := mbr.NextMessage() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { return nil, err diff --git a/worker/mbox/models.go b/worker/mbox/models.go index d98b14fd..849133c1 100644 --- a/worker/mbox/models.go +++ b/worker/mbox/models.go @@ -89,7 +89,7 @@ func (md *mailboxContainer) Copy(dest, src string, uids []uint32) error { } err = destmbox.Append(r, flags) if err != nil { - return fmt.Errorf("could not append data to mbox: %v", err) + return fmt.Errorf("could not append data to mbox: %w", err) } } } diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go index 6114870e..1e3ab982 100644 --- a/worker/mbox/worker.go +++ b/worker/mbox/worker.go @@ -2,6 +2,7 @@ package mboxer import ( "bytes" + "errors" "fmt" "io/ioutil" "net/url" @@ -113,12 +114,12 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { for _, uid := range w.folder.Uids() { m, err := w.folder.Message(uid) if err != nil { - logging.Errorf("could not get message %v", err) + logging.Errorf("could not get message %w", err) continue } info, err := lib.MessageInfo(m) if err != nil { - logging.Errorf("could not get message info %v", err) + logging.Errorf("could not get message info %w", err) continue } infos = append(infos, info) @@ -176,27 +177,27 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { case *types.FetchMessageBodyPart: m, err := w.folder.Message(msg.Uid) if err != nil { - logging.Errorf("could not get message %d: %v", msg.Uid, err) + logging.Errorf("could not get message %d: %w", msg.Uid, err) reterr = err break } contentReader, err := m.NewReader() if err != nil { - reterr = fmt.Errorf("could not get message reader: %v", err) + reterr = fmt.Errorf("could not get message reader: %w", err) break } fullMsg, err := gomessage.Read(contentReader) if err != nil { - reterr = fmt.Errorf("could not read message: %v", err) + reterr = fmt.Errorf("could not read message: %w", err) break } r, err := lib.FetchEntityPartReader(fullMsg, msg.Part) if err != nil { logging.Errorf( - "could not get body part reader for message=%d, parts=%#v: %v", + "could not get body part reader for message=%d, parts=%#v: %w", msg.Uid, msg.Part, err) reterr = err break @@ -214,18 +215,18 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { for _, uid := range msg.Uids { m, err := w.folder.Message(uid) if err != nil { - logging.Errorf("could not get message for uid %d: %v", uid, err) + logging.Errorf("could not get message for uid %d: %w", uid, err) continue } r, err := m.NewReader() if err != nil { - logging.Errorf("could not get message reader: %v", err) + logging.Errorf("could not get message reader: %w", err) continue } defer r.Close() b, err := ioutil.ReadAll(r) if err != nil { - logging.Errorf("could not get message reader: %v", err) + logging.Errorf("could not get message reader: %w", err) continue } w.worker.PostMessage(&types.FullMessage{ @@ -260,16 +261,16 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { for _, uid := range msg.Uids { m, err := w.folder.Message(uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) continue } if err := m.(*message).SetFlag(msg.Flag, msg.Enable); err != nil { - logging.Errorf("could change flag %v to %t on message: %v", msg.Flag, msg.Enable, err) + logging.Errorf("could change flag %v to %t on message: %w", msg.Flag, msg.Enable, err) continue } info, err := lib.MessageInfo(m) if err != nil { - logging.Errorf("could not get message info: %v", err) + logging.Errorf("could not get message info: %w", err) continue } @@ -365,7 +366,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { func (w *mboxWorker) Run() { for msg := range w.worker.Actions { msg = w.worker.ProcessAction(msg) - if err := w.handleMessage(msg); err == errUnsupported { + if err := w.handleMessage(msg); errors.Is(err, errUnsupported) { w.worker.PostMessage(&types.Unsupported{ Message: types.RespondTo(msg), }, nil) diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index e8a581c6..007a0a7e 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -4,6 +4,7 @@ package lib import ( + "errors" "fmt" "time" @@ -55,7 +56,7 @@ func (db *DB) connect(writable bool) error { var err error db.db, err = notmuch.Open(db.path, mode) if err != nil { - return fmt.Errorf("could not connect to notmuch db: %v", err) + return fmt.Errorf("could not connect to notmuch db: %w", err) } db.lastOpenTime = time.Now() return nil @@ -112,7 +113,7 @@ func (db *DB) newQuery(ndb *notmuch.DB, query string) (*notmuch.Query, error) { q.SetSortScheme(notmuch.SORT_OLDEST_FIRST) for _, t := range db.excludedTags { err := q.AddTagExclude(t) - if err != nil && err != notmuch.ErrIgnored { + if errors.Is(err, notmuch.ErrIgnored) { return nil, err } } diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go index fe82700e..a51f78b3 100644 --- a/worker/notmuch/message.go +++ b/worker/notmuch/message.go @@ -49,7 +49,7 @@ func (m *Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) { defer f.Close() msg, err := message.Read(f) if err != nil { - return nil, fmt.Errorf("could not read message: %v", err) + return nil, fmt.Errorf("could not read message: %w", err) } return lib.FetchEntityPartReader(msg, requestedParts) } diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index dba7857d..e6a9a492 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -7,6 +7,7 @@ import ( "bufio" "bytes" "context" + "errors" "fmt" "io/ioutil" "net/url" @@ -61,22 +62,22 @@ func (w *worker) Run() { select { case action := <-w.w.Actions: msg := w.w.ProcessAction(action) - if err := w.handleMessage(msg); err == errUnsupported { + if err := w.handleMessage(msg); errors.Is(err, errUnsupported) { w.w.PostMessage(&types.Unsupported{ Message: types.RespondTo(msg), }, nil) - logging.Errorf("ProcessAction(%T) unsupported: %v", msg, err) + logging.Errorf("ProcessAction(%T) unsupported: %w", msg, err) } else if err != nil { w.w.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, }, nil) - logging.Errorf("ProcessAction(%T) failure: %v", msg, err) + logging.Errorf("ProcessAction(%T) failure: %w", msg, err) } case nmEvent := <-w.nmEvents: err := w.handleNotmuchEvent(nmEvent) if err != nil { - logging.Errorf("notmuch event failure: %v", err) + logging.Errorf("notmuch event failure: %w", err) } } } @@ -157,22 +158,22 @@ func (w *worker) handleConfigure(msg *types.Configure) error { w.setupErr = nil return } - w.setupErr = fmt.Errorf("notmuch: %v", err) + w.setupErr = fmt.Errorf("notmuch: %w", err) }() u, err := url.Parse(msg.Config.Source) if err != nil { - logging.Errorf("error configuring notmuch worker: %v", err) + logging.Errorf("error configuring notmuch worker: %w", err) return err } home, err := homedir.Expand(u.Hostname()) if err != nil { - return fmt.Errorf("could not resolve home directory: %v", err) + return fmt.Errorf("could not resolve home directory: %w", err) } pathToDB := filepath.Join(home, u.Path) err = w.loadQueryMap(msg.Config) if err != nil { - return fmt.Errorf("could not load query map configuration: %v", err) + return fmt.Errorf("could not load query map configuration: %w", err) } excludedTags := w.loadExcludeTags(msg.Config) w.db = notmuch.NewDB(pathToDB, excludedTags) @@ -313,13 +314,13 @@ func (w *worker) handleFetchMessageHeaders( for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) w.err(msg, err) continue } err = w.emitMessageInfo(m, msg) if err != nil { - logging.Errorf("could not emit message info: %v", err) + logging.Errorf("could not emit message info: %w", err) w.err(msg, err) continue } @@ -360,13 +361,13 @@ func (w *worker) handleFetchMessageBodyPart( ) error { m, err := w.msgFromUid(msg.Uid) if err != nil { - logging.Errorf("could not get message %d: %v", msg.Uid, err) + logging.Errorf("could not get message %d: %w", msg.Uid, err) return err } r, err := m.NewBodyPartReader(msg.Part) if err != nil { logging.Errorf( - "could not get body part reader for message=%d, parts=%#v: %v", + "could not get body part reader for message=%d, parts=%#v: %w", msg.Uid, msg.Part, err) return err } @@ -386,12 +387,12 @@ func (w *worker) handleFetchFullMessages(msg *types.FetchFullMessages) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { - logging.Errorf("could not get message %d: %v", uid, err) + logging.Errorf("could not get message %d: %w", uid, err) return err } r, err := m.NewReader() if err != nil { - logging.Errorf("could not get message reader: %v", err) + logging.Errorf("could not get message reader: %w", err) return err } defer r.Close() @@ -415,24 +416,24 @@ func (w *worker) handleAnsweredMessages(msg *types.AnsweredMessages) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) w.err(msg, err) continue } if err := m.MarkAnswered(msg.Answered); err != nil { - logging.Errorf("could not mark message as answered: %v", err) + logging.Errorf("could not mark message as answered: %w", err) w.err(msg, err) continue } err = w.emitMessageInfo(m, msg) if err != nil { - logging.Errorf("could not emit message info: %v", err) + logging.Errorf("could not emit message info: %w", err) w.err(msg, err) continue } } if err := w.emitDirectoryInfo(w.currentQueryName); err != nil { - logging.Errorf("could not emit directory info: %v", err) + logging.Errorf("could not emit directory info: %w", err) } w.done(msg) return nil @@ -442,24 +443,24 @@ func (w *worker) handleFlagMessages(msg *types.FlagMessages) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) w.err(msg, err) continue } if err := m.SetFlag(msg.Flag, msg.Enable); err != nil { - logging.Errorf("could not set flag %v as %t for message: %v", msg.Flag, msg.Enable, err) + logging.Errorf("could not set flag %v as %t for message: %w", msg.Flag, msg.Enable, err) w.err(msg, err) continue } err = w.emitMessageInfo(m, msg) if err != nil { - logging.Errorf("could not emit message info: %v", err) + logging.Errorf("could not emit message info: %w", err) w.err(msg, err) continue } } if err := w.emitDirectoryInfo(w.currentQueryName); err != nil { - logging.Errorf("could not emit directory info: %v", err) + logging.Errorf("could not emit directory info: %w", err) } w.done(msg) return nil @@ -488,11 +489,11 @@ func (w *worker) handleModifyLabels(msg *types.ModifyLabels) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { - return fmt.Errorf("could not get message from uid %d: %v", uid, err) + return fmt.Errorf("could not get message from uid %d: %w", uid, err) } err = m.ModifyTags(msg.Add, msg.Remove) if err != nil { - return fmt.Errorf("could not modify message tags: %v", err) + return fmt.Errorf("could not modify message tags: %w", err) } err = w.emitMessageInfo(m, msg) if err != nil { @@ -508,7 +509,7 @@ func (w *worker) handleModifyLabels(msg *types.ModifyLabels) error { // and update the list of possible tags w.emitLabelList() if err = w.emitDirectoryInfo(w.currentQueryName); err != nil { - logging.Errorf("could not emit directory info: %v", err) + logging.Errorf("could not emit directory info: %w", err) } w.done(msg) return nil @@ -572,11 +573,11 @@ func (w *worker) emitDirectoryContents(parent types.WorkerMessage) error { } uids, err := w.uidsFromQuery(query) if err != nil { - return fmt.Errorf("could not fetch uids: %v", err) + return fmt.Errorf("could not fetch uids: %w", err) } sortedUids, err := w.sort(uids, w.currentSortCriteria) if err != nil { - logging.Errorf("error sorting directory: %v", err) + logging.Errorf("error sorting directory: %w", err) return err } w.w.PostMessage(&types.DirectoryContents{ @@ -609,7 +610,7 @@ func (w *worker) emitMessageInfo(m *Message, ) error { info, err := m.MessageInfo() if err != nil { - return fmt.Errorf("could not get MessageInfo: %v", err) + return fmt.Errorf("could not get MessageInfo: %w", err) } w.w.PostMessage(&types.MessageInfo{ Message: types.RespondTo(parent), @@ -621,7 +622,7 @@ func (w *worker) emitMessageInfo(m *Message, func (w *worker) emitLabelList() { tags, err := w.db.ListTags() if err != nil { - logging.Errorf("could not load tags: %v", err) + logging.Errorf("could not load tags: %w", err) return } w.w.PostMessage(&types.LabelList{Labels: tags}, nil) @@ -637,19 +638,19 @@ func (w *worker) sort(uids []uint32, for _, uid := range uids { m, err := w.msgFromUid(uid) if err != nil { - logging.Errorf("could not get message: %v", err) + logging.Errorf("could not get message: %w", err) continue } info, err := m.MessageInfo() if err != nil { - logging.Errorf("could not get message info: %v", err) + logging.Errorf("could not get message info: %w", err) continue } msgInfos = append(msgInfos, info) } sortedUids, err := lib.Sort(msgInfos, criteria) if err != nil { - logging.Errorf("could not sort the messages: %v", err) + logging.Errorf("could not sort the messages: %w", err) return nil, err } return sortedUids, nil @@ -673,7 +674,7 @@ func (w *worker) handleCheckMail(msg *types.CheckMail) { w.err(msg, fmt.Errorf("checkmail: timed out")) case err := <-ch: if err != nil { - w.err(msg, fmt.Errorf("checkmail: error running command: %v", err)) + w.err(msg, fmt.Errorf("checkmail: error running command: %w", err)) } else { w.done(msg) } diff --git a/worker/types/thread.go b/worker/types/thread.go index d37d2067..9f59e9e6 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -42,7 +42,7 @@ func (t *Thread) insertCmp(child *Thread, cmp func(*Thread, *Thread) bool) { func (t *Thread) Walk(walkFn NewThreadWalkFn) error { err := newWalk(t, walkFn, 0, nil) - if err == ErrSkipThread { + if errors.Is(err, ErrSkipThread) { return nil } return err @@ -80,7 +80,7 @@ func newWalk(node *Thread, walkFn NewThreadWalkFn, lvl int, ce error) error { } for child := node.FirstChild; child != nil; child = child.NextSibling { err = newWalk(child, walkFn, lvl+1, err) - if err == ErrSkipThread { + if errors.Is(err, ErrSkipThread) { err = nil continue } else if err != nil { |