From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Subject: [PATCH 09/10] emacs: Improve error handling for notmuch-call-notmuch-json
Date: Sat, 1 Dec 2012 21:40:01 -0500 [thread overview]
Message-ID: <1354416002-3557-9-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu>
This checks for non-zero exit status and pops up an error buffer
giving the exit status, the stderr, and the stdout. Schema version
mismatches are handled specially.
---
emacs/notmuch-lib.el | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 31c69dc..9c6be13 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -361,15 +361,41 @@ You may need to restart Emacs or upgrade your notmuch package."))
"Invoke `notmuch-command' with `args' and return the parsed JSON output.
The returned output will represent objects using property lists
-and arrays as lists."
+and arrays as lists. If notmuch exits with a non-zero status,
+this will pop up a buffer containing notmuch's output and signal
+an error."
(with-temp-buffer
- (apply #'call-process notmuch-command nil (list t nil) nil args)
- (goto-char (point-min))
- (let ((json-object-type 'plist)
- (json-array-type 'list)
- (json-false 'nil))
- (json-read))))
+ (let ((err-file (make-temp-file "nmerr")))
+ (unwind-protect
+ (let ((status (apply #'call-process
+ notmuch-command nil (list t err-file) nil args)))
+ (cond ((equal status 0)
+ (goto-char (point-min))
+ (let ((json-object-type 'plist)
+ (json-array-type 'list)
+ (json-false 'nil))
+ (json-read)))
+ ((or (equal status 20) (equal status 21))
+ ;; Special handling of version mismatch errors
+ (notmuch-version-mismatch-error status))
+ (t
+ (goto-char (point-min))
+ (insert "Error:\n")
+ (let ((pos (point)))
+ (insert-file-contents err-file)
+ (when (= (point) pos)
+ (insert "(no error output)\n")))
+ (unless (eobp)
+ (insert "Output:\n"))
+ (notmuch-pop-up-error
+ (concat
+ (format "CLI error. %S exited with %s%s.\n"
+ (cons notmuch-command args)
+ (if (integerp status) "status " "")
+ status)
+ (buffer-string))))))
+ (delete-file err-file)))))
;; Compatibility functions for versions of emacs before emacs 23.
;;
--
1.7.10.4
next prev parent reply other threads:[~2012-12-02 2:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-02 2:39 [PATCH 01/10] cli: Framework for structured output versioning Austin Clements
2012-12-02 2:39 ` [PATCH 02/10] search: Support --use-schema Austin Clements
2012-12-02 2:39 ` [PATCH 03/10] show: " Austin Clements
2012-12-02 2:39 ` [PATCH 04/10] reply: " Austin Clements
2012-12-02 2:39 ` [PATCH 05/10] test: Sanity tests for --use-schema argument Austin Clements
2012-12-02 2:39 ` [PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse error Austin Clements
2012-12-08 8:32 ` Mark Walters
2012-12-02 2:39 ` [PATCH 07/10] emacs: Use --use-schema for search Austin Clements
2012-12-08 8:48 ` Mark Walters
2012-12-13 1:43 ` Austin Clements
2012-12-13 11:00 ` Mark Walters
2012-12-02 2:40 ` [PATCH 08/10] emacs: Factor out synchronous notmuch JSON invocations Austin Clements
2012-12-02 2:40 ` Austin Clements [this message]
2012-12-02 2:40 ` [PATCH 10/10] emacs: Use --use-schema for show and reply Austin Clements
2012-12-03 0:58 ` [PATCH 00/10] CLI output versioning Austin Clements
2012-12-08 9:29 ` Mark Walters
2012-12-13 1:46 ` Austin Clements
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=1354416002-3557-9-git-send-email-amdragon@mit.edu \
--to=amdragon@mit.edu \
--cc=notmuch@notmuchmail.org \
/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).