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 62EB7431FDB for ; Sat, 15 Dec 2012 12:05:11 -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 n5ujKx6bLJFG for ; Sat, 15 Dec 2012 12:05:09 -0800 (PST) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by olra.theworths.org (Postfix) with ESMTP id 5B2CA431FCB for ; Sat, 15 Dec 2012 12:04:44 -0800 (PST) X-AuditID: 12074422-b7fe46d0000008d2-7f-50ccd7db87a6 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id F2.9D.02258.BD7DCC05; Sat, 15 Dec 2012 15:04:43 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qBFK4WAF014729; Sat, 15 Dec 2012 15:04:32 -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 qBFK4T5o025684 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 15 Dec 2012 15:04:31 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TjxyG-0007sY-Mr; Sat, 15 Dec 2012 15:04:28 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 4/7] emacs: Improve error handling for notmuch-call-notmuch-json Date: Sat, 15 Dec 2012 15:04:17 -0500 Message-Id: <1355601860-30121-5-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355601860-30121-1-git-send-email-amdragon@mit.edu> References: <1355601860-30121-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEIsWRmVeSWpSXmKPExsUixG6nonv7+pkAg3dP5SxWz+WxuH5zJrPF m5XzWB2YPXbOusvucfjrQhaPZ6tuMQcwR3HZpKTmZJalFunbJXBlvDm7krHgG09F0/2rrA2M c7i6GDk5JARMJFbf3skKYYtJXLi3nq2LkYtDSGAfo8THtp2MEM4GRontbz4wQTiPmCR2NE1j h3DmMkp8mLCYDaSfTUBDYtv+5YwgtoiAtMTOu7PB5jILxElsmfIfKM7BISwQLPH0nz9ImEVA VeLBkz1grbwCDhLHd7+FOkNRovvZBLA4p4CjxMTJu5hAbCGgmtsL5jBNYORfwMiwilE2JbdK NzcxM6c4NVm3ODkxLy+1SNdULzezRC81pXQTIzi4XJR2MP48qHSIUYCDUYmHd0fE6QAh1sSy 4srcQ4ySHExKorwZl88ECPEl5adUZiQWZ8QXleakFh9ilOBgVhLhTZoPlONNSaysSi3Kh0lJ c7AoifNeS7npLySQnliSmp2aWpBaBJOV4eBQkuCdeg2oUbAoNT21Ii0zpwQhzcTBCTKcB2j4 KZAa3uKCxNzizHSI/ClGXY6GlzeeMgqx5OXnpUqJ8y4EKRIAKcoozYObA0sKrxjFgd4S5t0C UsUDTChwk14BLWECWrLcBmxJSSJCSqqBUT9R3p93gYZf5pYtt2xUPQWO1zps05N6tKmoI/Hn wd5zfxj6c13+L7aYL8BQqtD7YlbeIsX9bA9OPd4nFB19bNrBVz7Kt+LdZolVSP9YWvbso+PK 9skXKn5rOspUnmX5cd1IWziLn+tIgoiEd8af17ldiml3N7QvO83JYbrh8nm3sqar79kalFiK MxINtZiLihMBu+HG4OUCAAA= Cc: tomi.ollila@iki.fi 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 20:05:11 -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 f534770..7f7022a 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -375,15 +375,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