unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Cc: tomi.ollila@iki.fi
Subject: [PATCH v2 6/7] emacs: Use unified error handling in search
Date: Sat, 15 Dec 2012 15:04:19 -0500	[thread overview]
Message-ID: <1355601860-30121-7-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1355601860-30121-1-git-send-email-amdragon@mit.edu>

This slightly changes the output of an existing test since we now
report non-zero exits with a pop-up buffer instead of at the end of
the search results.
---
 emacs/notmuch-lib.el           |   13 +++++++++++++
 emacs/notmuch.el               |   13 ++++++++-----
 test/emacs-large-search-buffer |    2 +-
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 7f7022a..8f84087 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -334,6 +334,19 @@ the user dismisses it."
 	  (insert "\n"))))
     (pop-to-buffer buf)))
 
+(defun notmuch-check-async-exit-status (proc msg)
+  "If PROC exited abnormally, pop up an error buffer and signal an error.
+
+This is a wrapper around `notmuch-check-exit-status' for
+asynchronous process sentinels.  PROC and MSG must be the
+arguments passed to the sentinel."
+  (let ((exit-status
+	 (case (process-status proc)
+	   ((exit) (process-exit-status proc))
+	   ((signal) msg))))
+    (when exit-status
+      (notmuch-check-exit-status exit-status (process-command proc)))))
+
 (defun notmuch-check-exit-status (exit-status command &optional output err-file)
   "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.
 
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 9da8df4..b0fd387 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -638,6 +638,7 @@ of the result."
 	(exit-status (process-exit-status proc))
 	(never-found-target-thread nil))
     (when (memq status '(exit signal))
+      (catch 'return
 	(kill-buffer (process-get proc 'parse-buf))
 	(if (buffer-live-p buffer)
 	    (with-current-buffer buffer
@@ -648,17 +649,19 @@ of the result."
 		  (if (eq status 'signal)
 		      (insert "Incomplete search results (search process was killed).\n"))
 		  (when (eq status 'exit)
-		    (insert "End of search results.")
-		    (unless (= exit-status 0)
-		      (insert (format " (process returned %d)" exit-status)))
-		    (insert "\n")
+		    (insert "End of search results.\n")
+		    (condition-case nil
+			(notmuch-check-async-exit-status proc msg)
+		      ;; Suppress the error signal since strange
+		      ;; things happen if a sentinel signals.
+		      (error (throw 'return nil)))
 		    (if (and atbob
 			     (not (string= notmuch-search-target-thread "found")))
 			(set 'never-found-target-thread t)))))
 	      (when (and never-found-target-thread
 		       notmuch-search-target-line)
 		  (goto-char (point-min))
-		  (forward-line (1- notmuch-search-target-line))))))))
+		  (forward-line (1- notmuch-search-target-line)))))))))
 
 (defcustom notmuch-search-line-faces '(("unread" :weight bold)
 				       ("flagged" :foreground "blue"))
diff --git a/test/emacs-large-search-buffer b/test/emacs-large-search-buffer
index 678328d..9dcbef5 100755
--- a/test/emacs-large-search-buffer
+++ b/test/emacs-large-search-buffer
@@ -36,7 +36,7 @@ test_emacs '(notmuch-search "--this-option-does-not-exist")
 cat <<EOF >EXPECTED
 Error: Unexpected output from notmuch search:
 Unrecognized option: --this-option-does-not-exist
-End of search results. (process returned 1)
+End of search results.
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
-- 
1.7.10.4

  parent reply	other threads:[~2012-12-15 20:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-15 20:04 [PATCH v2 0/7] Improve Emacs CLI error handling Austin Clements
2012-12-15 20:04 ` [PATCH v2 1/7] emacs: Centralize notmuch command " Austin Clements
2012-12-16 21:39   ` David Bremner
2012-12-15 20:04 ` [PATCH v2 2/7] emacs: Use unified error handling in notmuch-call-notmuch-process Austin Clements
2012-12-15 20:04 ` [PATCH v2 3/7] emacs: Factor out synchronous notmuch JSON invocations Austin Clements
2012-12-15 20:04 ` [PATCH v2 4/7] emacs: Improve error handling for notmuch-call-notmuch-json Austin Clements
2012-12-15 20:04 ` [PATCH v2 5/7] test: Test show's handling of subprocess errors Austin Clements
2012-12-15 20:04 ` Austin Clements [this message]
2012-12-15 20:04 ` [PATCH v2 7/7] test: Test search's " Austin Clements
2012-12-16  1:19 ` [PATCH v2 0/7] Improve Emacs CLI error handling Mark Walters
2012-12-16  3:08 ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1355601860-30121-7-git-send-email-amdragon@mit.edu \
    --to=amdragon@mit.edu \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).