Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 08156431FBD for ; Sat, 1 Dec 2012 18:40:16 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a+42A1gttsWM for ; Sat, 1 Dec 2012 18:40:15 -0800 (PST) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id CA33A431FC3 for ; Sat, 1 Dec 2012 18:40:13 -0800 (PST) X-AuditID: 12074425-b7f606d0000008ea-2a-50babf8d2d00 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 19.75.02282.D8FBAB05; Sat, 1 Dec 2012 21:40:13 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qB22eBuO030585; Sat, 1 Dec 2012 21:40:11 -0500 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB22e65n025605 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 1 Dec 2012 21:40:10 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TezTS-0000xn-55; Sat, 01 Dec 2012 21:40:06 -0500 From: Austin Clements 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 Message-Id: <1354416002-3557-9-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu> References: <1354416002-3557-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrdu7f1eAwcNOQYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEr49v2s0wFiwUrNtz/wdjAOJe3i5GDQ0LARGLZDLsuRk4gU0zi wr31bF2MXBxCAvsYJdYfnskK4axnlJjVfpsFwnnIJLFk8z82kBYhgbmMEvfv5YLYbAIaEtv2 L2cEsUUEpCV23p3NCrKBWUBN4k+XCkhYWCBIou/XVBYQm0VAVWLPpG+sIDavgL1E05Z2Rogr FCW6n01gA2nlFHCQWNHNA7HJXuL/72tsExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdK1 0MvNLNFLTSndxAgKGHYX1R2MEw4pHWIU4GBU4uGNmLMrQIg1say4MvcQoyQHk5Io75UdQCG+ pPyUyozE4oz4otKc1OJDjBIczEoivCwmQDnelMTKqtSifJiUNAeLkjjvjZSb/kIC6Yklqdmp qQWpRTBZGQ4OJQne6n1AjYJFqempFWmZOSUIaSYOTpDhPEDDp4HU8BYXJOYWZ6ZD5E8xKkqJ 83aCJARAEhmleXC9sIh+xSgO9Iow72GQKh5gMoDrfgU0mAlo8Jtl20EGlyQipKQaGJOVBBMK TfYoSGovuVzmbLuXuXiL1JH3H+xWaMTN6CybsbU4ZePxZQYXJB/uTmpR0tBY2hyyeGVlbJzA H225/jv3HF+ohok8SqvPu2ZXyb6Rs1bZNPXQjPTlM2/aLfFuETLZZ3Pkw+ZbyU8ONPF9lOUt vcRZFiHF98nlxuVTDW36k2dcdfu7XImlOCPRUIu5qDgRAE9JeV/DAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Dec 2012 02:40:16 -0000 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