[PATCH 8/8] cli: optionally restore message properties from dump file
[notmuch-archives.git] / a5 / c20c21755f5c467b1e930d0b090d10d5ecaf7a
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 206BA431FAF\r
6         for <notmuch@notmuchmail.org>; Wed,  2 Jan 2013 16:50:34 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 XoI05Sb0HRqE for <notmuch@notmuchmail.org>;\r
16         Wed,  2 Jan 2013 16:50:32 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
18         [18.9.25.13])\r
19         by olra.theworths.org (Postfix) with ESMTP id 0D155431FAE\r
20         for <notmuch@notmuchmail.org>; Wed,  2 Jan 2013 16:50:31 -0800 (PST)\r
21 X-AuditID: 1209190d-b7efd6d000001a82-43-50e4d5d75c15\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 27.85.06786.7D5D4E05; Wed,  2 Jan 2013 19:50:31 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r030oTOg026185; \r
27         Wed, 2 Jan 2013 19:50:29 -0500\r
28 Received: from drake.dyndns.org (a069.catapulsion.net [70.36.81.69])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id r030oQqV005751\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Wed, 2 Jan 2013 19:50:28 -0500 (EST)\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1TqZ0r-0006Y1-7C; Wed, 02 Jan 2013 19:50:25 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v2] emacs: Use the minibuffer for CLI error reporting\r
40 Date: Wed,  2 Jan 2013 19:50:22 -0500\r
41 Message-Id: <1357174222-25132-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 In-Reply-To: <1356724088-26032-1-git-send-email-amdragon@mit.edu>\r
44 References: <1356724088-26032-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFjrHIsWRmVeSWpSXmKPExsUixCmqrHv96pMAg33b1CxutHYzWuzZ52Wx\r
47         ei6PxfWbM5kdWDzunuby2DnrLrvHs1W3mD22HHrPHMASxWWTkpqTWZZapG+XwJWxt6eRqWCx\r
48         W8W9m/cZGxi/mnUxcnJICJhILN7zkxHCFpO4cG89WxcjF4eQwD5GiaPdM1hBEkIC6xklHi/n\r
49         h0jsZ5J40XCTHcKZyyhx78oNZpAqNgENiW37l4ONEhGQlth5dzZYN7NApcSci9PBbGEBV4kV\r
50         qy6wgdgsAqoSB3YcBevlFXCQ6G7vZ4I4Q1Gi+9kEsBpOAUeJ5p/zmSCucJA4sPEI8wRG/gWM\r
51         DKsYZVNyq3RzEzNzilOTdYuTE/PyUot0jfRyM0v0UlNKNzGCg02Sdwfju4NKhxgFOBiVeHgZ\r
52         6p8ECLEmlhVX5h5ilORgUhLlzb8IFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCez0HKMebklhZ\r
53         lVqUD5OS5mBREue9knLTX0ggPbEkNTs1tSC1CCYrw8GhJMFrdQWoUbAoNT21Ii0zpwQhzcTB\r
54         CTKcB2h4KkgNb3FBYm5xZjpE/hSjopQ4bxBIQgAkkVGaB9cLSwavGMWBXhHmLQSp4gEmErju\r
55         V0CDmYAGv3rzGGRwSSJCSqqBcfVydo5v5QIVu1J9y6903bA3lXm4SfdJVpxdu+KFWe8WfJI6\r
56         fvvi9QWFa/9d/LH5bEBp2YKgqtjjTSe4ChMjLy9f9tZLsIdvlXurS7TomaptQW2MdW8D9534\r
57         Xbo33nySaQWTxfG7TRxHl0+43DHzeMHaMNbJVvdP3e0xFdfc+fTKwRnhtcqcXEosxRmJhlrM\r
58         RcWJAGd921rhAgAA\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Thu, 03 Jan 2013 00:50:34 -0000\r
72 \r
73 We recently switched to popping up a buffer to report CLI errors, but\r
74 this was too intrusive, especially for transient errors and especially\r
75 since we made fewer things ignore errors.  This patch changes this to\r
76 display a basic error message in the minibuffer (using Emacs' usual\r
77 error handling path) and, if there are additional details, to log\r
78 these to a separate error buffer and reference the error buffer from\r
79 the minibuffer message.  This is more in line with how Emacs typically\r
80 handles errors, but makes the details available to the user without\r
81 flooding them with the details.\r
82 \r
83 Given this split, we pare down the basic message and make it more\r
84 user-friendly, and also make the verbose message even more detailed\r
85 (and more debugging-oriented).\r
86 ---\r
87  emacs/notmuch-lib.el |   92 ++++++++++++++++++++++++++++----------------------\r
88  emacs/notmuch.el     |    9 +++--\r
89  test/emacs           |   19 ++++++++---\r
90  test/emacs-show      |   26 ++++++++++----\r
91  4 files changed, 90 insertions(+), 56 deletions(-)\r
92 \r
93 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
94 index 77a591d..d78bcf8 100644\r
95 --- a/emacs/notmuch-lib.el\r
96 +++ b/emacs/notmuch-lib.el\r
97 @@ -316,23 +316,28 @@ string), a property list of face attributes, or a list of these."\r
98         (put-text-property pos next 'face (cons face cur))\r
99         (setq pos next)))))\r
100  \r
101 -(defun notmuch-pop-up-error (msg)\r
102 -  "Pop up an error buffer displaying MSG.\r
103 -\r
104 -This will accumulate error messages in the errors buffer until\r
105 -the user dismisses it."\r
106 -\r
107 -  (let ((buf (get-buffer-create "*Notmuch errors*")))\r
108 -    (with-current-buffer buf\r
109 -      (view-mode-enter nil #'kill-buffer)\r
110 -      (let ((inhibit-read-only t))\r
111 -       (goto-char (point-max))\r
112 -       (unless (bobp)\r
113 -         (insert "\n"))\r
114 -       (insert msg)\r
115 +(defun notmuch-logged-error (msg &optional extra)\r
116 +  "Log MSG and EXTRA to *Notmuch errors* and signal MSG.\r
117 +\r
118 +This logs MSG and EXTRA to the *Notmuch errors* buffer and\r
119 +signals MSG as an error.  If EXTRA is non-nil, text referring the\r
120 +user to the *Notmuch errors* buffer will be appended to the\r
121 +signaled error.  This function does not return."\r
122 +\r
123 +  (with-current-buffer (get-buffer-create "*Notmuch errors*")\r
124 +    (goto-char (point-max))\r
125 +    (unless (bobp)\r
126 +      (newline))\r
127 +    (save-excursion\r
128 +      (insert "[" (current-time-string) "]\n" msg)\r
129 +      (unless (bolp)\r
130 +       (newline))\r
131 +      (when extra\r
132 +       (insert extra)\r
133         (unless (bolp)\r
134 -         (insert "\n"))))\r
135 -    (pop-to-buffer buf)))\r
136 +         (newline)))))\r
137 +  (error "%s" (concat msg (when extra\r
138 +                           " (see *Notmuch errors* for more details)"))))\r
139  \r
140  (defun notmuch-check-async-exit-status (proc msg)\r
141    "If PROC exited abnormally, pop up an error buffer and signal an error.\r
142 @@ -363,35 +368,40 @@ contents of ERR-FILE will be included in the error message."\r
143    (cond\r
144     ((eq exit-status 0) t)\r
145     ((eq exit-status 20)\r
146 -    (notmuch-pop-up-error "Error: Version mismatch.\r
147 +    (notmuch-logged-error "notmuch CLI version mismatch\r
148  Emacs requested an older output format than supported by the notmuch CLI.\r
149 -You may need to restart Emacs or upgrade your notmuch Emacs package.")\r
150 -    (error "notmuch CLI version mismatch"))\r
151 +You may need to restart Emacs or upgrade your notmuch Emacs package."))\r
152     ((eq exit-status 21)\r
153 -    (notmuch-pop-up-error "Error: Version mismatch.\r
154 +    (notmuch-logged-error "notmuch CLI version mismatch\r
155  Emacs requested a newer output format than supported by the notmuch CLI.\r
156 -You may need to restart Emacs or upgrade your notmuch package.")\r
157 -    (error "notmuch CLI version mismatch"))\r
158 +You may need to restart Emacs or upgrade your notmuch package."))\r
159     (t\r
160 -    (notmuch-pop-up-error\r
161 -     (concat\r
162 -      (format "Error invoking notmuch.  %s exited with %s%s.\n"\r
163 -             (mapconcat #'identity command " ")\r
164 -             ;; Signal strings look like "Terminated", hence the\r
165 -             ;; colon.\r
166 -             (if (integerp exit-status) "status " "signal: ")\r
167 -             exit-status)\r
168 -      (when err-file\r
169 -       (concat "Error:\n"\r
170 -               (with-temp-buffer\r
171 -                 (insert-file-contents err-file)\r
172 -                 (if (eobp)\r
173 -                     "(no error output)\n"\r
174 -                   (buffer-string)))))\r
175 -      (when (and output (not (equal output "")))\r
176 -       (format "Output:\n%s" output))))\r
177 -    ;; Mimic `process-lines'\r
178 -    (error "%s exited with status %s" (car command) exit-status))))\r
179 +    (let* ((err (when err-file\r
180 +                 (with-temp-buffer\r
181 +                   (insert-file-contents err-file)\r
182 +                   (unless (eobp)\r
183 +                     (buffer-string)))))\r
184 +          (extra\r
185 +           (concat\r
186 +            "command: " (mapconcat #'shell-quote-argument command " ") "\n"\r
187 +            (if (integerp exit-status)\r
188 +                (format "exit status: %s\n" exit-status)\r
189 +              (format "exit signal: %s\n" exit-status))\r
190 +            (when err\r
191 +              (concat "stderr:\n" err))\r
192 +            (when output\r
193 +              (concat "stdout:\n" output)))))\r
194 +       (if err\r
195 +           ;; We have an error message straight from the CLI.\r
196 +           (notmuch-logged-error\r
197 +            (replace-regexp-in-string "\\s $" "" err) extra)\r
198 +         ;; We only have combined output from the CLI; don't inundate\r
199 +         ;; the user with it.  Mimic `process-lines'.\r
200 +         (notmuch-logged-error (format "%s exited with status %s"\r
201 +                                       (car command) exit-status)\r
202 +                               extra))\r
203 +       ;; `notmuch-logged-error' does not return.\r
204 +       ))))\r
205  \r
206  (defun notmuch-call-notmuch-json (&rest args)\r
207    "Invoke `notmuch-command' with `args' and return the parsed JSON output.\r
208 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
209 index 63387a2..c98a4fe 100644\r
210 --- a/emacs/notmuch.el\r
211 +++ b/emacs/notmuch.el\r
212 @@ -654,11 +654,14 @@ of the result."\r
213                     ;; showing the search buffer\r
214                     (when (or (= exit-status 20) (= exit-status 21))\r
215                       (kill-buffer))\r
216 -                   (condition-case nil\r
217 +                   (condition-case err\r
218                         (notmuch-check-async-exit-status proc msg)\r
219                       ;; Suppress the error signal since strange\r
220 -                     ;; things happen if a sentinel signals.\r
221 -                     (error (throw 'return nil)))\r
222 +                     ;; things happen if a sentinel signals.  Mimic\r
223 +                     ;; the top-level's handling of error messages.\r
224 +                     (error\r
225 +                      (message "%s" (second err))\r
226 +                      (throw 'return nil)))\r
227                     (if (and atbob\r
228                              (not (string= notmuch-search-target-thread "found")))\r
229                         (set 'never-found-target-thread t)))))\r
230 diff --git a/test/emacs b/test/emacs\r
231 index 6b18968..c7bd150 100755\r
232 --- a/test/emacs\r
233 +++ b/test/emacs\r
234 @@ -862,18 +862,27 @@ exit 1\r
235  EOF\r
236  chmod a+x notmuch_fail\r
237  test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
238 +              (with-current-buffer \"*Messages*\" (erase-buffer))\r
239                (notmuch-search \"tag:inbox\")\r
240                (notmuch-test-wait)\r
241 -              (test-output)\r
242 +              (with-current-buffer \"*Messages*\"\r
243 +                 (test-output \"MESSAGES\"))\r
244                (with-current-buffer \"*Notmuch errors*\"\r
245 -                 (test-output \"ERROR\")))"\r
246 -test_expect_equal "$(cat OUTPUT ERROR)" "\\r
247 +                 (test-output \"ERROR\"))\r
248 +              (test-output))"\r
249 +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
250 +test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
251  Error: Unexpected output from notmuch search:\r
252  This is output\r
253  Error: Unexpected output from notmuch search:\r
254  This is an error\r
255  End of search results.\r
256 -Error invoking notmuch.  $PWD/notmuch_fail search --format=json --format-version=1 --sort=newest-first tag:inbox exited with status 1."\r
257 -\r
258 +---\r
259 +$PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
260 +---\r
261 +[XXX]\r
262 +/tmp/nmtest/tmp.emacs/notmuch_fail exited with status 1\r
263 +command: /tmp/nmtest/tmp.emacs/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox\r
264 +exit status: 1"\r
265  \r
266  test_done\r
267 diff --git a/test/emacs-show b/test/emacs-show\r
268 index ebf530b..9f2ccb0 100755\r
269 --- a/test/emacs-show\r
270 +++ b/test/emacs-show\r
271 @@ -172,16 +172,28 @@ exit 1\r
272  EOF\r
273  chmod a+x notmuch_fail\r
274  test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
275 -              (ignore-errors (notmuch-show \"*\"))\r
276 +              (with-current-buffer \"*Messages*\" (erase-buffer))\r
277 +              (condition-case err\r
278 +                  (notmuch-show \"*\")\r
279 +                (error (message \"%s\" (second err))))\r
280                (notmuch-test-wait)\r
281 -              (test-output)\r
282 +              (with-current-buffer \"*Messages*\"\r
283 +                 (test-output \"MESSAGES\"))\r
284                (with-current-buffer \"*Notmuch errors*\"\r
285 -                 (test-output \"ERROR\")))"\r
286 -test_expect_equal "$(cat OUTPUT ERROR)" "\\r
287 -Error invoking notmuch.  $PWD/notmuch_fail show --format=json --format-version=1 --exclude=false ' * ' exited with status 1.\r
288 -Error:\r
289 +                 (test-output \"ERROR\"))\r
290 +              (test-output))"\r
291 +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
292 +test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
293 +---\r
294 +This is an error (see *Notmuch errors* for more details)\r
295 +---\r
296 +[XXX]\r
297  This is an error\r
298 -Output:\r
299 +command: $PWD/notmuch_fail show --format\\=json --format-version\\=1 --exclude\\=false \\' \\* \\'\r
300 +exit status: 1\r
301 +stderr:\r
302 +This is an error\r
303 +stdout:\r
304  This is output"\r
305  \r
306  \r
307 -- \r
308 1.7.10.4\r
309 \r