1 Return-Path: <amdragon@mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 6BD3E431FC0
\r
6 for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 12:04:34 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 2oimcf8eyHgo for <notmuch@notmuchmail.org>;
\r
16 Sat, 15 Dec 2012 12:04:33 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 3CC03431FB6
\r
20 for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 12:04:33 -0800 (PST)
\r
21 X-AuditID: 1209190e-b7f516d0000008e4-e2-50ccd7d0b881
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 4E.06.02276.0D7DCC05; Sat, 15 Dec 2012 15:04:32 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBFK4Vlj013137;
\r
27 Sat, 15 Dec 2012 15:04:31 -0500
\r
28 Received: from drake.dyndns.org
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBFK4Sp7025681
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sat, 15 Dec 2012 15:04:30 -0500 (EST)
\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)
\r
36 (envelope-from <amdragon@mit.edu>)
\r
37 id 1TjxyG-0007sR-IF; Sat, 15 Dec 2012 15:04:28 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH v2 1/7] emacs: Centralize notmuch command error handling
\r
41 Date: Sat, 15 Dec 2012 15:04:14 -0500
\r
42 Message-Id: <1355601860-30121-2-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.10.4
\r
44 In-Reply-To: <1355601860-30121-1-git-send-email-amdragon@mit.edu>
\r
45 References: <1355601860-30121-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrnvh+pkAg95OJYvVc3ksrt+cyWzx
\r
48 ZuU8Vgdmj52z7rJ7HP66kMXj2apbzAHMUVw2Kak5mWWpRfp2CVwZl48/ZCvYJVYxZ9U5xgbG
\r
49 W4JdjBwcEgImEh+eCnUxcgKZYhIX7q1n62Lk4hAS2Mco0fuhmxnC2cAose30bFYI5xGTxKLW
\r
50 7YwQzlxGiUc7X7KB9LMJaEhs27+cEcQWEZCW2HkXpIOTg1kgTmLLlP9gcWEBD4lDJy8wgdgs
\r
51 AqoSTRM2gtm8Ag4SZ3sPskHcoSjR/WwCmM0p4CgxcfIusBohoJrbC+YwTWDkX8DIsIpRNiW3
\r
52 Sjc3MTOnODVZtzg5MS8vtUjXWC83s0QvNaV0EyMouDgl+XYwfj2odIhRgINRiYd3R8TpACHW
\r
53 xLLiytxDjJIcTEqivBmXzwQI8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuFNmg+U401JrKxKLcqH
\r
54 SUlzsCiJ815JuekvJJCeWJKanZpakFoEk5Xh4FCS4BUCRpGQYFFqempFWmZOCUKaiYMTZDgP
\r
55 0HAOkBre4oLE3OLMdIj8KUZFKXFeO5CEAEgiozQPrhcW/a8YxYFeEeb9cA2oigeYOOC6XwEN
\r
56 ZgIavNwGbHBJIkJKqoHR3Ujeepppw6aZ0dVdiYuWisiyPip9LzCTp0h50vrtGXvajOfvqfy8
\r
57 0NTvwaNFJg8WGs1x+lE7b52xoLstS5uZosWbCdO4PC7XzmXTlvd5tPiBWfeCsD8OG9I/9PV+
\r
58 yfm1d8XESeoaBwRfPUhqyzj64MJJidpZSV+bW14b33q7Jmvuhm8PjdeJKLEUZyQaajEXFScC
\r
60 Cc: tomi.ollila@iki.fi
\r
61 X-BeenThere: notmuch@notmuchmail.org
\r
62 X-Mailman-Version: 2.1.13
\r
64 List-Id: "Use and development of the notmuch mail system."
\r
65 <notmuch.notmuchmail.org>
\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
69 List-Post: <mailto:notmuch@notmuchmail.org>
\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
73 X-List-Received-Date: Sat, 15 Dec 2012 20:04:34 -0000
\r
75 This provides library functions for unified handling of errors from
\r
76 the notmuch CLI. Follow-up patches will convert some scattered error
\r
77 handling to use this and add error handling where we currently ignore
\r
80 emacs/notmuch-lib.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
81 1 file changed, 55 insertions(+)
\r
83 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
\r
84 index 9c4ee71..f757ce7 100644
\r
85 --- a/emacs/notmuch-lib.el
\r
86 +++ b/emacs/notmuch-lib.el
\r
87 @@ -316,6 +316,61 @@ string), a property list of face attributes, or a list of these."
\r
88 (put-text-property pos next 'face (cons face cur))
\r
91 +(defun notmuch-pop-up-error (msg)
\r
92 + "Pop up an error buffer displaying MSG.
\r
94 +This will accumulate error messages in the errors buffer until
\r
95 +the user dismisses it."
\r
97 + (let ((buf (get-buffer-create "*Notmuch errors*")))
\r
98 + (with-current-buffer buf
\r
99 + (view-mode-enter nil #'kill-buffer)
\r
100 + (let ((inhibit-read-only t))
\r
101 + (goto-char (point-max))
\r
107 + (pop-to-buffer buf)))
\r
109 +(defun notmuch-check-exit-status (exit-status command &optional output err-file)
\r
110 + "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.
\r
112 +If EXIT-STATUS is non-zero, pop up a notmuch error buffer
\r
113 +describing the error and signal an Elisp error. EXIT-STATUS must
\r
114 +be a number indicating the exit status code of a process or a
\r
115 +string describing the signal that terminated the process (such as
\r
116 +returned by `call-process'). COMMAND must be a list giving the
\r
117 +command and its arguments. OUTPUT, if provided, is a string
\r
118 +giving the output of command. ERR-FILE, if provided, is the name
\r
119 +of a file containing the error output of command. OUTPUT and the
\r
120 +contents of ERR-FILE will be included in the error message."
\r
122 + ;; This is implemented as a cond to make it easy to expand.
\r
124 + ((eq exit-status 0) t)
\r
126 + (notmuch-pop-up-error
\r
128 + (format "Error invoking notmuch. %s exited with %s%s.\n"
\r
129 + (mapconcat #'identity command " ")
\r
130 + ;; Signal strings look like "Terminated", hence the
\r
132 + (if (integerp exit-status) "status " "signal: ")
\r
135 + (concat "Error:\n"
\r
136 + (with-temp-buffer
\r
137 + (insert-file-contents err-file)
\r
139 + "(no error output)\n"
\r
140 + (buffer-string)))))
\r
141 + (when (and output (not (equal output "")))
\r
142 + (format "Output:\n%s" output))))
\r
143 + ;; Mimic `process-lines'
\r
144 + (error "%s exited with status %s" (car command) exit-status))))
\r
146 ;; Compatibility functions for versions of emacs before emacs 23.
\r
148 ;; Both functions here were copied from emacs 23 with the following copyright:
\r