aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-10-02 11:36:05 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-02 18:56:26 +0200
commitdc299cc8adda5c9fb7a0f6a7719f3e2cd0f1f443 (patch)
tree5a3e0ded9d72ae0eafa3440e2ee1c88109d9c21a
parent020279108c4234974a26580183ef60945c5bd5cb (diff)
downloadaerc-dc299cc8adda5c9fb7a0f6a7719f3e2cd0f1f443.tar.gz
logging: substitute %w for %v
Subsitute the format specifier %w for %v in the logging facility. The logging functions use a fmt.Sprintf call behind the scene which does not recognize %w. %w should be used in fmt.Errorf when you want to wrap errors. Hence, the log entries that use %w are improperly formatted like this: ERROR 2022/10/02 09:13:57.724529 worker.go:439: could not get message info %!w(*fmt.wrapError=&{could not get structure: [snip] }) ^ Links: https://go.dev/blog/go1.13-errors Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
-rw-r--r--commands/msg/forward.go2
-rw-r--r--commands/msg/pipe.go2
-rw-r--r--lib/msgstore.go2
-rw-r--r--widgets/msgviewer.go2
-rw-r--r--widgets/terminal.go2
-rw-r--r--worker/maildir/worker.go56
-rw-r--r--worker/mbox/worker.go18
-rw-r--r--worker/notmuch/worker.go46
-rw-r--r--worker/types/thread.go2
9 files changed, 66 insertions, 66 deletions
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index 040360ea..a3459292 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -143,7 +143,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
defer tmpFile.Close()
_, err = io.Copy(tmpFile, fm.Content.Reader)
if err != nil {
- logging.Warnf("failed to write to tmpfile: %w", err)
+ logging.Warnf("failed to write to tmpfile: %v", err)
return
}
composer, err := addTab()
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index 29d63baf..89dbc47c 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -98,7 +98,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
defer pipe.Close()
_, err := io.Copy(pipe, reader)
if err != nil {
- logging.Errorf("failed to send data to pipe: %w", err)
+ logging.Errorf("failed to send data to pipe: %v", err)
}
}()
err = ecmd.Run()
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 44de7010..d2d4b6e6 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -433,7 +433,7 @@ func (store *MessageStore) SelectedThread() *types.Thread {
return nil
})
if err != nil {
- logging.Errorf("SelectedThread failed: %w", err)
+ logging.Errorf("SelectedThread failed: %v", err)
}
if found {
break
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index d5d1d279..126bf85b 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -667,7 +667,7 @@ func (pv *PartViewer) attemptCopy() {
// if it's binary we have to rely on the filter to be sane
_, err := io.Copy(pv.sink, pv.source)
if err != nil {
- logging.Warnf("failed to copy: %w", err)
+ logging.Warnf("failed to copy: %v", err)
}
}
pv.sink.Close()
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 894bdf09..b854a288 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -84,7 +84,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
term.vterm.Watch(term)
attr := &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1}
if err := term.vterm.StartWithAttrs(term.cmd, attr); err != nil {
- logging.Errorf("error running terminal: %w", err)
+ logging.Errorf("error running terminal: %v", err)
term.Close(err)
return
}
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index d0619ad4..3ac8d0b3 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -111,7 +111,7 @@ func (w *Worker) handleFSEvent(ev fsnotify.Event) {
}
err := w.c.SyncNewMail(*w.selected)
if err != nil {
- logging.Errorf("could not move new to cur : %w", err)
+ logging.Errorf("could not move new to cur : %v", err)
return
}
@@ -190,18 +190,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): %w", v, key, err)
+ logging.Errorf("%q: error parsing flags (%q): %v", v, key, err)
continue
}
keyFlags[key] = flags
}
} else {
- logging.Infof("disabled flags cache: %q: %w", dir, err)
+ logging.Infof("disabled flags cache: %q: %v", dir, err)
}
uids, err := w.c.UIDs(dir)
if err != nil {
- logging.Errorf("could not get uids: %w", err)
+ logging.Errorf("could not get uids: %v", err)
return dirInfo
}
@@ -209,7 +209,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: %w", err)
+ logging.Errorf("could not get message: %v", err)
continue
}
var flags []maildir.Flag
@@ -220,14 +220,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: %w", err)
+ logging.Errorf("could not get flags: %v", err)
continue
}
}
} else {
flags, err = message.Flags()
if err != nil {
- logging.Errorf("could not get flags: %w", err)
+ logging.Errorf("could not get flags: %v", err)
continue
}
}
@@ -294,7 +294,7 @@ 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: %w", err)
+ logging.Errorf("error configuring maildir worker: %v", err)
return err
}
dir := u.Path
@@ -331,7 +331,7 @@ func (w *Worker) handleListDirectories(msg *types.ListDirectories) error {
}
dirs, err := w.c.ListFolders()
if err != nil {
- logging.Errorf("failed listing directories: %w", err)
+ logging.Errorf("failed listing directories: %v", err)
return err
}
for _, name := range dirs {
@@ -414,13 +414,13 @@ func (w *Worker) handleFetchDirectoryContents(
} else {
uids, err = w.c.UIDs(*w.selected)
if err != nil {
- logging.Errorf("failed scanning uids: %w", err)
+ logging.Errorf("failed scanning uids: %v", err)
return err
}
}
sortedUids, err := w.sort(uids, msg.SortCriteria)
if err != nil {
- logging.Errorf("failed sorting directory: %w", err)
+ logging.Errorf("failed sorting directory: %v", err)
return err
}
w.currentSortCriteria = msg.SortCriteria
@@ -439,14 +439,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: %w", err)
+ logging.Errorf("could not get message info: %v", err)
continue
}
msgInfos = append(msgInfos, info)
}
sortedUids, err := lib.Sort(msgInfos, criteria)
if err != nil {
- logging.Errorf("could not sort the messages: %w", err)
+ logging.Errorf("could not sort the messages: %v", err)
return nil, err
}
return sortedUids, nil
@@ -455,7 +455,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: %w",
+ logging.Errorf("could not create directory %s: %v",
msg.Directory, err)
return err
}
@@ -465,7 +465,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: %w",
+ logging.Errorf("could not remove directory %s: %v",
msg.Directory, err)
return err
}
@@ -478,7 +478,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: %w", err)
+ logging.Errorf("could not get message info: %v", err)
w.worker.PostMessageInfoError(msg, uid, err)
continue
}
@@ -497,7 +497,7 @@ 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: %w", msg.Uid, err)
+ logging.Errorf("could not get message %d: %v", msg.Uid, err)
return err
}
r, err := m.NewBodyPartReader(msg.Part)
@@ -522,12 +522,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: %w", uid, err)
+ logging.Errorf("could not get message %d: %v", uid, err)
return err
}
r, err := m.NewReader()
if err != nil {
- logging.Errorf("could not get message reader: %w", err)
+ logging.Errorf("could not get message reader: %v", err)
return err
}
defer r.Close()
@@ -558,7 +558,7 @@ func (w *Worker) handleDeleteMessages(msg *types.DeleteMessages) error {
}, nil)
}
if err != nil {
- logging.Errorf("failed removing messages: %w", err)
+ logging.Errorf("failed removing messages: %v", err)
return err
}
return nil
@@ -568,18 +568,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: %w", err)
+ logging.Errorf("could not get message: %v", err)
w.err(msg, err)
continue
}
if err := m.MarkReplied(msg.Answered); err != nil {
- logging.Errorf("could not mark message as answered: %w", err)
+ logging.Errorf("could not mark message as answered: %v", err)
w.err(msg, err)
continue
}
info, err := m.MessageInfo()
if err != nil {
- logging.Errorf("could not get message info: %w", err)
+ logging.Errorf("could not get message info: %v", err)
w.err(msg, err)
continue
}
@@ -600,19 +600,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: %w", err)
+ logging.Errorf("could not get message: %v", 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: %w", flag, msg.Enable, err)
+ logging.Errorf("could change flag %v to %v on message: %v", flag, msg.Enable, err)
w.err(msg, err)
continue
}
info, err := m.MessageInfo()
if err != nil {
- logging.Errorf("could not get message info: %w", err)
+ logging.Errorf("could not get message info: %v", err)
w.err(msg, err)
continue
}
@@ -663,12 +663,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: %w", msg.Destination, err)
+ logging.Errorf("could not create message at %s: %v", 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: %w", err)
+ logging.Errorf("could not write message to destination: %v", err)
return err
}
w.worker.PostMessage(&types.Done{
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index 10a94cdc..a786a65e 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -167,7 +167,7 @@ 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: %w", msg.Uid, err)
+ logging.Errorf("could not get message %d: %v", msg.Uid, err)
reterr = err
break
}
@@ -205,18 +205,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: %w", uid, err)
+ logging.Errorf("could not get message for uid %d: %v", uid, err)
continue
}
r, err := m.NewReader()
if err != nil {
- logging.Errorf("could not get message reader: %w", err)
+ logging.Errorf("could not get message reader: %v", err)
continue
}
defer r.Close()
b, err := io.ReadAll(r)
if err != nil {
- logging.Errorf("could not get message reader: %w", err)
+ logging.Errorf("could not get message reader: %v", err)
continue
}
w.worker.PostMessage(&types.FullMessage{
@@ -251,16 +251,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: %w", err)
+ logging.Errorf("could not get message: %v", err)
continue
}
if err := m.(*message).SetFlag(msg.Flag, msg.Enable); err != nil {
- logging.Errorf("could change flag %v to %t on message: %w", msg.Flag, msg.Enable, err)
+ logging.Errorf("could change flag %v to %t on message: %v", msg.Flag, msg.Enable, err)
continue
}
info, err := lib.MessageInfo(m)
if err != nil {
- logging.Errorf("could not get message info: %w", err)
+ logging.Errorf("could not get message info: %v", err)
continue
}
@@ -397,12 +397,12 @@ func sortUids(folder *container, uids []uint32,
for _, uid := range uids {
m, err := folder.Message(uid)
if err != nil {
- logging.Errorf("could not get message %w", err)
+ logging.Errorf("could not get message %v", err)
continue
}
info, err := lib.MessageInfo(m)
if err != nil {
- logging.Errorf("could not get message info %w", err)
+ logging.Errorf("could not get message info %v", err)
continue
}
infos = append(infos, info)
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 1ceaac8d..f1533e12 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -66,18 +66,18 @@ func (w *worker) Run() {
w.w.PostMessage(&types.Unsupported{
Message: types.RespondTo(msg),
}, nil)
- logging.Errorf("ProcessAction(%T) unsupported: %w", msg, err)
+ logging.Errorf("ProcessAction(%T) unsupported: %v", msg, err)
} else if err != nil {
w.w.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
- logging.Errorf("ProcessAction(%T) failure: %w", msg, err)
+ logging.Errorf("ProcessAction(%T) failure: %v", msg, err)
}
case nmEvent := <-w.nmEvents:
err := w.handleNotmuchEvent(nmEvent)
if err != nil {
- logging.Errorf("notmuch event failure: %w", err)
+ logging.Errorf("notmuch event failure: %v", err)
}
}
}
@@ -163,7 +163,7 @@ func (w *worker) handleConfigure(msg *types.Configure) error {
u, err := url.Parse(msg.Config.Source)
if err != nil {
- logging.Errorf("error configuring notmuch worker: %w", err)
+ logging.Errorf("error configuring notmuch worker: %v", err)
return err
}
home, err := homedir.Expand(u.Hostname())
@@ -318,13 +318,13 @@ func (w *worker) handleFetchMessageHeaders(
for _, uid := range msg.Uids {
m, err := w.msgFromUid(uid)
if err != nil {
- logging.Errorf("could not get message: %w", err)
+ logging.Errorf("could not get message: %v", err)
w.w.PostMessageInfoError(msg, uid, err)
continue
}
err = w.emitMessageInfo(m, msg)
if err != nil {
- logging.Errorf("could not emit message info: %w", err)
+ logging.Errorf("could not emit message info: %v", err)
w.w.PostMessageInfoError(msg, uid, err)
continue
}
@@ -365,7 +365,7 @@ func (w *worker) handleFetchMessageBodyPart(
) error {
m, err := w.msgFromUid(msg.Uid)
if err != nil {
- logging.Errorf("could not get message %d: %w", msg.Uid, err)
+ logging.Errorf("could not get message %d: %v", msg.Uid, err)
return err
}
r, err := m.NewBodyPartReader(msg.Part)
@@ -391,12 +391,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: %w", uid, err)
+ logging.Errorf("could not get message %d: %v", uid, err)
return err
}
r, err := m.NewReader()
if err != nil {
- logging.Errorf("could not get message reader: %w", err)
+ logging.Errorf("could not get message reader: %v", err)
return err
}
defer r.Close()
@@ -420,24 +420,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: %w", err)
+ logging.Errorf("could not get message: %v", err)
w.err(msg, err)
continue
}
if err := m.MarkAnswered(msg.Answered); err != nil {
- logging.Errorf("could not mark message as answered: %w", err)
+ logging.Errorf("could not mark message as answered: %v", err)
w.err(msg, err)
continue
}
err = w.emitMessageInfo(m, msg)
if err != nil {
- logging.Errorf("could not emit message info: %w", err)
+ logging.Errorf("could not emit message info: %v", err)
w.err(msg, err)
continue
}
}
if err := w.emitDirectoryInfo(w.currentQueryName); err != nil {
- logging.Errorf("could not emit directory info: %w", err)
+ logging.Errorf("could not emit directory info: %v", err)
}
w.done(msg)
return nil
@@ -447,24 +447,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: %w", err)
+ logging.Errorf("could not get message: %v", 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: %w", msg.Flag, msg.Enable, err)
+ logging.Errorf("could not set flag %v as %t for message: %v", 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: %w", err)
+ logging.Errorf("could not emit message info: %v", err)
w.err(msg, err)
continue
}
}
if err := w.emitDirectoryInfo(w.currentQueryName); err != nil {
- logging.Errorf("could not emit directory info: %w", err)
+ logging.Errorf("could not emit directory info: %v", err)
}
w.done(msg)
return nil
@@ -513,7 +513,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: %w", err)
+ logging.Errorf("could not emit directory info: %v", err)
}
w.done(msg)
return nil
@@ -581,7 +581,7 @@ func (w *worker) emitDirectoryContents(parent types.WorkerMessage) error {
}
sortedUids, err := w.sort(uids, w.currentSortCriteria)
if err != nil {
- logging.Errorf("error sorting directory: %w", err)
+ logging.Errorf("error sorting directory: %v", err)
return err
}
w.w.PostMessage(&types.DirectoryContents{
@@ -626,7 +626,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: %w", err)
+ logging.Errorf("could not load tags: %v", err)
return
}
w.w.PostMessage(&types.LabelList{Labels: tags}, nil)
@@ -642,19 +642,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: %w", err)
+ logging.Errorf("could not get message: %v", err)
continue
}
info, err := m.MessageInfo()
if err != nil {
- logging.Errorf("could not get message info: %w", err)
+ logging.Errorf("could not get message info: %v", err)
continue
}
msgInfos = append(msgInfos, info)
}
sortedUids, err := lib.Sort(msgInfos, criteria)
if err != nil {
- logging.Errorf("could not sort the messages: %w", err)
+ logging.Errorf("could not sort the messages: %v", err)
return nil, err
}
return sortedUids, nil
diff --git a/worker/types/thread.go b/worker/types/thread.go
index 60ecc7ce..177cd310 100644
--- a/worker/types/thread.go
+++ b/worker/types/thread.go
@@ -72,7 +72,7 @@ func (t *Thread) Uids() []uint32 {
return nil
})
if err != nil {
- logging.Errorf("walk to collect uids failed: %w", err)
+ logging.Errorf("walk to collect uids failed: %v", err)
}
return uids
}