unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* bug: notmuch-poll doesn't check return value
@ 2015-09-14 12:18 Ketil Malde
  2015-10-28 18:28 ` [PATCH] emacs: poll: return useful errors when poll fails Mark Walters
  0 siblings, 1 reply; 4+ messages in thread
From: Ketil Malde @ 2015-09-14 12:18 UTC (permalink / raw)
  To: notmuch


Hi,

I've been stumped occasionally when new mail fails to appear in notmuch,
and then I suddenly discover it by some other means (web front end,
mobile, etc).

The problem is that notmuch-poll fails silently when it fails, which is
usually due to broken symlinks in my mail directories, or some IMAP
configuration mistake.  Easy to fix when you know about it.

I've, uh, "fixed" this by redefining notmuch-poll like so:

---8<-------------------------------------
;;; Make notmuch-poll fail gracelessly when something goes wrong
;;; Better than failing silently, in ancy case.
(defun notmuch-poll ()
  "Run \"notmuch new\" or an external script to import mail.

Invokes `notmuch-poll-script', \"notmuch new\", or does nothing
depending on the value of `notmuch-poll-script'."
  (interactive)
  (if (not (equal 0
		  (if (stringp notmuch-poll-script)
		      (unless (string= notmuch-poll-script "")
			(call-process notmuch-poll-script nil nil))
		    (call-process notmuch-command nil nil nil "new"))))
     (error "Notmuch: poll failed!")))
---8<-------------------------------------

Surely, somebody who knows lisp can do something far more elegant than
this, but the point is to bug out when something doesn't work.

In addtion, I had to fix my notmuch-poll-script, which contains
'offlineimap', then 'notmuch new', followed by some tagging commands.
As the tagging commands tend to work even if 'new' doesn't, this will
often (pretend to) exit successfully.  A 'set -e' at the top of the
script is probably a good idea, and should probably be mentioned in
documentation somewhere.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] emacs: poll: return useful errors when poll fails.
  2015-09-14 12:18 bug: notmuch-poll doesn't check return value Ketil Malde
@ 2015-10-28 18:28 ` Mark Walters
  2015-10-28 20:18   ` Tomi Ollila
  2015-11-23 12:51   ` David Bremner
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Walters @ 2015-10-28 18:28 UTC (permalink / raw)
  To: notmuch, ketil

Previously poll called from emacs would fail silently. This makes it
return a useful error message.

In the non-deprecated case of notmuch new and appropriate hooks, it
uses notmuch-call-notmuch-process which gives an error and
additionally puts the stdout/stderr etc in the *Notmuch errors*
buffer.

In the deprecated case of a custom poll script it only returns an
error message.

Commit based on a bug report, and a potential fix, by Ketil Malde.
---

This should fix the bug reported in the parent message -- we should
definitely report error messages. It might be nice to output the
stdout/stderr in the custom poll script case but since we don't have
built in infrastructure for it it probably isn't worth it for a
deprecated case.

(Note I don't use poll, so this is not heavily tested)

Best wishes

Mark



 emacs/notmuch-lib.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 1c3a9fe..89c01a5 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -243,8 +243,9 @@ depending on the value of `notmuch-poll-script'."
   (interactive)
   (if (stringp notmuch-poll-script)
       (unless (string= notmuch-poll-script "")
-	(call-process notmuch-poll-script nil nil))
-    (call-process notmuch-command nil nil nil "new")))
+	(unless (equal (call-process notmuch-poll-script nil nil) 0)
+	  (error "Notmuch: poll script `%s' failed!" notmuch-poll-script)))
+    (notmuch-call-notmuch-process "new")))
 
 (defun notmuch-bury-or-kill-this-buffer ()
   "Undisplay the current buffer.
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] emacs: poll: return useful errors when poll fails.
  2015-10-28 18:28 ` [PATCH] emacs: poll: return useful errors when poll fails Mark Walters
@ 2015-10-28 20:18   ` Tomi Ollila
  2015-11-23 12:51   ` David Bremner
  1 sibling, 0 replies; 4+ messages in thread
From: Tomi Ollila @ 2015-10-28 20:18 UTC (permalink / raw)
  To: Mark Walters, notmuch, ketil

On Wed, Oct 28 2015, Mark Walters <markwalters1009@gmail.com> wrote:

> Previously poll called from emacs would fail silently. This makes it
> return a useful error message.
>
> In the non-deprecated case of notmuch new and appropriate hooks, it
> uses notmuch-call-notmuch-process which gives an error and
> additionally puts the stdout/stderr etc in the *Notmuch errors*
> buffer.
>
> In the deprecated case of a custom poll script it only returns an
> error message.
>
> Commit based on a bug report, and a potential fix, by Ketil Malde.
> ---

Looks good (to me) -- I investigated a bit how notmuch-call-notmuch-process
does things; it uses notmuch-check-exit-status which is not applicable 
here.

Mark said he doesn't use poll -- and I have rewritten my poll(*) so my
tests will be as lightweight as his. So we wait for Ketil's report
how this works :D

Tomi

(*) see at the end of this email

>
> This should fix the bug reported in the parent message -- we should
> definitely report error messages. It might be nice to output the
> stdout/stderr in the custom poll script case but since we don't have
> built in infrastructure for it it probably isn't worth it for a
> deprecated case.
>
> (Note I don't use poll, so this is not heavily tested)
>
> Best wishes
>
> Mark
>

For reference, if anyone gets ideas from this...

;; overwrite notmuch-poll defined in notmuch.el
(defun notmuch-poll ()
  (interactive)
  (save-window-excursion
    (let ((buffer (get-buffer-create "*my notmuch polls*")))
      (set-buffer buffer)
      (setq buffer-read-only nil)
      (goto-char (point-max))
      (pop-to-buffer buffer)
      (call-process "notmuch-log-output.sh" nil t t "new" "--verbose")
      (bury-buffer))) ;; <- b-b to put the buffer at the "bottom" of buffers
  (message "update finished"))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] emacs: poll: return useful errors when poll fails.
  2015-10-28 18:28 ` [PATCH] emacs: poll: return useful errors when poll fails Mark Walters
  2015-10-28 20:18   ` Tomi Ollila
@ 2015-11-23 12:51   ` David Bremner
  1 sibling, 0 replies; 4+ messages in thread
From: David Bremner @ 2015-11-23 12:51 UTC (permalink / raw)
  To: Mark Walters, notmuch, ketil

Mark Walters <markwalters1009@gmail.com> writes:

> Previously poll called from emacs would fail silently. This makes it
> return a useful error message.
>
> In the non-deprecated case of notmuch new and appropriate hooks, it
> uses notmuch-call-notmuch-process which gives an error and
> additionally puts the stdout/stderr etc in the *Notmuch errors*
> buffer.
>
> In the deprecated case of a custom poll script it only returns an
> error message.
>
> Commit based on a bug report, and a potential fix, by Ketil Malde.

applied to release and master

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-23 13:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-14 12:18 bug: notmuch-poll doesn't check return value Ketil Malde
2015-10-28 18:28 ` [PATCH] emacs: poll: return useful errors when poll fails Mark Walters
2015-10-28 20:18   ` Tomi Ollila
2015-11-23 12:51   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).