[PATCH v2 4/7] emacs: Improve error handling for notmuch-call-notmuch-json
authorAustin Clements <amdragon@MIT.EDU>
Sat, 15 Dec 2012 20:04:17 +0000 (15:04 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:20 +0000 (09:52 -0800)
ad/fe72041674939e9b2e1a54b5d9a2b5eaa69f91 [new file with mode: 0644]

diff --git a/ad/fe72041674939e9b2e1a54b5d9a2b5eaa69f91 b/ad/fe72041674939e9b2e1a54b5d9a2b5eaa69f91
new file mode 100644 (file)
index 0000000..034fc9a
--- /dev/null
@@ -0,0 +1,120 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 62EB7431FDB\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 12:05:11 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id n5ujKx6bLJFG for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 12:05:09 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+       [18.7.68.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5B2CA431FCB\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 12:04:44 -0800 (PST)\r
+X-AuditID: 12074422-b7fe46d0000008d2-7f-50ccd7db87a6\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id F2.9D.02258.BD7DCC05; Sat, 15 Dec 2012 15:04:43 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qBFK4WAF014729; \r
+       Sat, 15 Dec 2012 15:04:32 -0500\r
+Received: from drake.dyndns.org\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBFK4T5o025684\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 15 Dec 2012 15:04:31 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TjxyG-0007sY-Mr; Sat, 15 Dec 2012 15:04:28 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 4/7] emacs: Improve error handling for\r
+       notmuch-call-notmuch-json\r
+Date: Sat, 15 Dec 2012 15:04:17 -0500\r
+Message-Id: <1355601860-30121-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1355601860-30121-1-git-send-email-amdragon@mit.edu>\r
+References: <1355601860-30121-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrEIsWRmVeSWpSXmKPExsUixG6nonv7+pkAg3dP5SxWz+WxuH5zJrPF\r
+       m5XzWB2YPXbOusvucfjrQhaPZ6tuMQcwR3HZpKTmZJalFunbJXBlvDm7krHgG09F0/2rrA2M\r
+       c7i6GDk5JARMJFbf3skKYYtJXLi3nq2LkYtDSGAfo8THtp2MEM4GRontbz4wQTiPmCR2NE1j\r
+       h3DmMkp8mLCYDaSfTUBDYtv+5YwgtoiAtMTOu7PB5jILxElsmfIfKM7BISwQLPH0nz9ImEVA\r
+       VeLBkz1grbwCDhLHd7+FOkNRovvZBLA4p4CjxMTJu5hAbCGgmtsL5jBNYORfwMiwilE2JbdK\r
+       NzcxM6c4NVm3ODkxLy+1SNdULzezRC81pXQTIzi4XJR2MP48qHSIUYCDUYmHd0fE6QAh1sSy\r
+       4srcQ4ySHExKorwZl88ECPEl5adUZiQWZ8QXleakFh9ilOBgVhLhTZoPlONNSaysSi3Kh0lJ\r
+       c7AoifNeS7npLySQnliSmp2aWpBaBJOV4eBQkuCdeg2oUbAoNT21Ii0zpwQhzcTBCTKcB2j4\r
+       KZAa3uKCxNzizHSI/ClGXY6GlzeeMgqx5OXnpUqJ8y4EKRIAKcoozYObA0sKrxjFgd4S5t0C\r
+       UsUDTChwk14BLWECWrLcBmxJSSJCSqqBUT9R3p93gYZf5pYtt2xUPQWO1zps05N6tKmoI/Hn\r
+       wd5zfxj6c13+L7aYL8BQqtD7YlbeIsX9bA9OPd4nFB19bNrBVz7Kt+LdZolVSP9YWvbso+PK\r
+       9skXKn5rOspUnmX5cd1IWziLn+tIgoiEd8af17ldiml3N7QvO83JYbrh8nm3sqar79kalFiK\r
+       MxINtZiLihMBu+HG4OUCAAA=\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 15 Dec 2012 20:05:11 -0000\r
+\r
+This checks for non-zero exit status from JSON CLI calls and pops up\r
+an error buffer with stderr and stdout.  A consequence of this is that\r
+show and reply now handle errors, rather than ignoring them.\r
+---\r
+ emacs/notmuch-lib.el |   22 +++++++++++++++-------\r
+ 1 file changed, 15 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index f534770..7f7022a 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -375,15 +375,23 @@ contents of ERR-FILE will be included in the error message."\r
+   "Invoke `notmuch-command' with `args' and return the parsed JSON output.\r
\r
+ The returned output will represent objects using property lists\r
+-and arrays as lists."\r
++and arrays as lists.  If notmuch exits with a non-zero status,\r
++this will pop up a buffer containing notmuch's output and signal\r
++an error."\r
\r
+   (with-temp-buffer\r
+-    (apply #'call-process notmuch-command nil (list t nil) nil args)\r
+-    (goto-char (point-min))\r
+-    (let ((json-object-type 'plist)\r
+-        (json-array-type 'list)\r
+-        (json-false 'nil))\r
+-      (json-read))))\r
++    (let ((err-file (make-temp-file "nmerr")))\r
++      (unwind-protect\r
++        (let ((status (apply #'call-process\r
++                             notmuch-command nil (list t err-file) nil args)))\r
++          (notmuch-check-exit-status status (cons notmuch-command args)\r
++                                     (buffer-string) err-file)\r
++          (goto-char (point-min))\r
++          (let ((json-object-type 'plist)\r
++                (json-array-type 'list)\r
++                (json-false 'nil))\r
++            (json-read)))\r
++      (delete-file err-file)))))\r
\r
+ ;; Compatibility functions for versions of emacs before emacs 23.\r
+ ;;\r
+-- \r
+1.7.10.4\r
+\r