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 DDDFD431FD7 for ; Fri, 14 Dec 2012 21:15:28 -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 JJJNuW+yDBr4 for ; Fri, 14 Dec 2012 21:15:28 -0800 (PST) Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU [18.7.68.35]) by olra.theworths.org (Postfix) with ESMTP id 553E9431FBF for ; Fri, 14 Dec 2012 21:15:28 -0800 (PST) X-AuditID: 12074423-b7fcb6d000000927-fc-50cc076f0c30 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id 8A.A1.02343.F670CC05; Sat, 15 Dec 2012 00:15:27 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBF5FQQj020494; Sat, 15 Dec 2012 00:15:26 -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 qBF5FO2o011446 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 15 Dec 2012 00:15:26 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1Tjk5s-0002kU-8U; Sat, 15 Dec 2012 00:15:24 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 4/7] emacs: Improve error handling for notmuch-call-notmuch-json Date: Sat, 15 Dec 2012 00:15:10 -0500 Message-Id: <1355548513-10085-5-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355548513-10085-1-git-send-email-amdragon@mit.edu> References: <1355548513-10085-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRmVeSWpSXmKPExsUixG6nrpvPfibA4PYcY4vVc3ksrt+cyezA 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZSzecJO94BtPxcW/M5gbGOdwdTFyckgImEhM +bGeBcIWk7hwbz1bFyMXh5DAPkaJB+1LGSGcDYwSExasY4ZwHjFJTOu8xQ7hzGWUOLTlDSNI P5uAhsS2/cvBbBEBaYmdd2ezgtjMAo4Sn/cvYgOxhQUCJGZNXwxWwyKgKnG/7RKYzSvgINH3 /gY7xB2KEt3PJoDVcwL1Lvt4Duw+IaCas6/usk5g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEv L7VI10wvN7NELzWldBMjOJRclHcw/jmodIhRgINRiYd3Z8TpACHWxLLiytxDjJIcTEqivLcY zgQI8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuEV2wJUzpuSWFmVWpQPk5LmYFES572WctNfSCA9 sSQ1OzW1ILUIJivDwaEkwdvMBjRUsCg1PbUiLTOnBCHNxMEJMpwHaDgXSA1vcUFibnFmOkT+ FKMuR8PLG08ZhVjy8vNSpcR5n7ACFQmAFGWU5sHNgaWAV4ziQG8J80aDjOIBpg+4Sa+AljAB LYm7dBxkSUkiQkqqgXH6Ac7pEu7rRbT5p6iLbe6df/DAm7pHrb8OLymWTxA423K2Zk/phNj3 z0wkrpc5ZC0U3My0iun+rCurwqqa5MVCvlxST5tjun/q4Qo/iatZbr3b3164vWFe9c3A8FSZ p82vp+u6FQUq/NnQqjR1c63ENx6hE4K3VBg1uG9ctrVkc3F4nfEzo0uJpTgj0VCLuag4EQDp A3L13AIAAA== 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: Sat, 15 Dec 2012 05:15:29 -0000 This checks for non-zero exit status from JSON CLI calls and pops up an error buffer with stderr and stdout. A consequence of this is that show and reply now handle errors, rather than ignoring them. --- emacs/notmuch-lib.el | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 4b71116..9222de8 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -373,15 +373,23 @@ contents of ERR-FILE will be included in the error message." "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))) + (notmuch-check-exit-status status (cons notmuch-command args) + (buffer-string) err-file) + (goto-char (point-min)) + (let ((json-object-type 'plist) + (json-array-type 'list) + (json-false 'nil)) + (json-read))) + (delete-file err-file))))) ;; Compatibility functions for versions of emacs before emacs 23. ;; -- 1.7.10.4