[PATCH v2 1/7] emacs: Centralize notmuch command error handling
authorAustin Clements <amdragon@MIT.EDU>
Sat, 15 Dec 2012 20:04:14 +0000 (15:04 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:19 +0000 (09:52 -0800)
31/9fabe48f75265f58a0691197c56203236e77b0 [new file with mode: 0644]

diff --git a/31/9fabe48f75265f58a0691197c56203236e77b0 b/31/9fabe48f75265f58a0691197c56203236e77b0
new file mode 100644 (file)
index 0000000..7a49afe
--- /dev/null
@@ -0,0 +1,151 @@
+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 6BD3E431FC0\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 12:04:34 -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 2oimcf8eyHgo for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 12:04:33 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
+       [18.9.25.14])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3CC03431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 12:04:33 -0800 (PST)\r
+X-AuditID: 1209190e-b7f516d0000008e4-e2-50ccd7d0b881\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 4E.06.02276.0D7DCC05; Sat, 15 Dec 2012 15:04:32 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBFK4Vlj013137; \r
+       Sat, 15 Dec 2012 15:04:31 -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 qBFK4Sp7025681\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 15 Dec 2012 15:04:30 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TjxyG-0007sR-IF; Sat, 15 Dec 2012 15:04:28 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 1/7] emacs: Centralize notmuch command error handling\r
+Date: Sat, 15 Dec 2012 15:04:14 -0500\r
+Message-Id: <1355601860-30121-2-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+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrnvh+pkAg95OJYvVc3ksrt+cyWzx\r
+       ZuU8Vgdmj52z7rJ7HP66kMXj2apbzAHMUVw2Kak5mWWpRfp2CVwZl48/ZCvYJVYxZ9U5xgbG\r
+       W4JdjBwcEgImEh+eCnUxcgKZYhIX7q1n62Lk4hAS2Mco0fuhmxnC2cAose30bFYI5xGTxKLW\r
+       7YwQzlxGiUc7X7KB9LMJaEhs27+cEcQWEZCW2HkXpIOTg1kgTmLLlP9gcWEBD4lDJy8wgdgs\r
+       AqoSTRM2gtm8Ag4SZ3sPskHcoSjR/WwCmM0p4CgxcfIusBohoJrbC+YwTWDkX8DIsIpRNiW3\r
+       Sjc3MTOnODVZtzg5MS8vtUjXWC83s0QvNaV0EyMouDgl+XYwfj2odIhRgINRiYd3R8TpACHW\r
+       xLLiytxDjJIcTEqivBmXzwQI8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuFNmg+U401JrKxKLcqH\r
+       SUlzsCiJ815JuekvJJCeWJKanZpakFoEk5Xh4FCS4BUCRpGQYFFqempFWmZOCUKaiYMTZDgP\r
+       0HAOkBre4oLE3OLMdIj8KUZFKXFeO5CEAEgiozQPrhcW/a8YxYFeEeb9cA2oigeYOOC6XwEN\r
+       ZgIavNwGbHBJIkJKqoHR3Ujeepppw6aZ0dVdiYuWisiyPip9LzCTp0h50vrtGXvajOfvqfy8\r
+       0NTvwaNFJg8WGs1x+lE7b52xoLstS5uZosWbCdO4PC7XzmXTlvd5tPiBWfeCsD8OG9I/9PV+\r
+       yfm1d8XESeoaBwRfPUhqyzj64MJJidpZSV+bW14b33q7Jmvuhm8PjdeJKLEUZyQaajEXFScC\r
+       AKWLEf/ZAgAA\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:04:34 -0000\r
+\r
+This provides library functions for unified handling of errors from\r
+the notmuch CLI.  Follow-up patches will convert some scattered error\r
+handling to use this and add error handling where we currently ignore\r
+errors.\r
+---\r
+ emacs/notmuch-lib.el |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 55 insertions(+)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 9c4ee71..f757ce7 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -316,6 +316,61 @@ string), a property list of face attributes, or a list of these."\r
+       (put-text-property pos next 'face (cons face cur))\r
+       (setq pos next)))))\r
\r
++(defun notmuch-pop-up-error (msg)\r
++  "Pop up an error buffer displaying MSG.\r
++\r
++This will accumulate error messages in the errors buffer until\r
++the user dismisses it."\r
++\r
++  (let ((buf (get-buffer-create "*Notmuch errors*")))\r
++    (with-current-buffer buf\r
++      (view-mode-enter nil #'kill-buffer)\r
++      (let ((inhibit-read-only t))\r
++      (goto-char (point-max))\r
++      (unless (bobp)\r
++        (insert "\n"))\r
++      (insert msg)\r
++      (unless (bolp)\r
++        (insert "\n"))))\r
++    (pop-to-buffer buf)))\r
++\r
++(defun notmuch-check-exit-status (exit-status command &optional output err-file)\r
++  "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.\r
++\r
++If EXIT-STATUS is non-zero, pop up a notmuch error buffer\r
++describing the error and signal an Elisp error.  EXIT-STATUS must\r
++be a number indicating the exit status code of a process or a\r
++string describing the signal that terminated the process (such as\r
++returned by `call-process').  COMMAND must be a list giving the\r
++command and its arguments.  OUTPUT, if provided, is a string\r
++giving the output of command.  ERR-FILE, if provided, is the name\r
++of a file containing the error output of command.  OUTPUT and the\r
++contents of ERR-FILE will be included in the error message."\r
++\r
++  ;; This is implemented as a cond to make it easy to expand.\r
++  (cond\r
++   ((eq exit-status 0) t)\r
++   (t\r
++    (notmuch-pop-up-error\r
++     (concat\r
++      (format "Error invoking notmuch.  %s exited with %s%s.\n"\r
++            (mapconcat #'identity command " ")\r
++            ;; Signal strings look like "Terminated", hence the\r
++            ;; colon.\r
++            (if (integerp exit-status) "status " "signal: ")\r
++            exit-status)\r
++      (when err-file\r
++      (concat "Error:\n"\r
++              (with-temp-buffer\r
++                (insert-file-contents err-file)\r
++                (if (eobp)\r
++                    "(no error output)\n"\r
++                  (buffer-string)))))\r
++      (when (and output (not (equal output "")))\r
++      (format "Output:\n%s" output))))\r
++    ;; Mimic `process-lines'\r
++    (error "%s exited with status %s" (car command) exit-status))))\r
++\r
+ ;; Compatibility functions for versions of emacs before emacs 23.\r
+ ;;\r
+ ;; Both functions here were copied from emacs 23 with the following copyright:\r
+-- \r
+1.7.10.4\r
+\r