Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 4b / b060558738d675664a5d109f62944ef614bea2
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 880DE431FAF\r
6         for <notmuch@notmuchmail.org>; Thu,  3 Jan 2013 13:47:59 -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 NgsAuSWl8UVB for <notmuch@notmuchmail.org>;\r
16         Thu,  3 Jan 2013 13:47:58 -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 6A87F431FAE\r
20         for <notmuch@notmuchmail.org>; Thu,  3 Jan 2013 13:47:58 -0800 (PST)\r
21 X-AuditID: 1209190d-b7efd6d000001a82-c4-50e5fc8cd7fe\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 3B.2E.06786.C8CF5E05; Thu,  3 Jan 2013 16:47:56 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r03LlsT3001005; \r
27         Thu, 3 Jan 2013 16:47:54 -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 r03Llob5000054\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 3 Jan 2013 16:47:53 -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 1Tqsdi-0004j1-9K; Thu, 03 Jan 2013 16:47:50 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v3] emacs: Use the minibuffer for CLI error reporting\r
40 Date: Thu,  3 Jan 2013 16:47:49 -0500\r
41 Message-Id: <1357249669-9706-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 In-Reply-To: <1357174222-25132-1-git-send-email-amdragon@mit.edu>\r
44 References: <1357174222-25132-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsUixG6notvz52mAwea/3BY3WrsZLfbs87JY\r
47         PZfH4vrNmcwOLB53T3N57Jx1l93j2apbzB5bDr1nDmCJ4rJJSc3JLEst0rdL4MrYMeEuc8Ee\r
48         t4pbPUINjA3mXYycHBICJhKTPs5lhrDFJC7cW88GYgsJ7GOUuHVDoouRC8hezygx/f8URghn\r
49         P5PE6V3LWSGcuYwSH4+1sYO0sAloSGzbv5wRxBYRkJbYeXc2K4jNLFApMefidCCbg0NYwFXi\r
50         2bkIEJNFQFXiwdpyEJNXwF5i+kM3iBsUJbqfTQC7gVPAUeL33hZmiHscJP49ncY4gZF/ASPD\r
51         KkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0jvdzMEr3UlNJNjKAg45Tk3cH47qDSIUYBDkYlHt4J\r
52         954GCLEmlhVX5h5ilORgUhLlrfoOFOJLyk+pzEgszogvKs1JLT7EKMHBrCTC++42UI43JbGy\r
53         KrUoHyYlzcGiJM57JeWmv5BAemJJanZqakFqEUxWhoNDSYJ30m+gRsGi1PTUirTMnBKENBMH\r
54         J8hwHqDhySA1vMUFibnFmekQ+VOMilLivEtAEgIgiYzSPLheWBJ4xSgO9IowbydIFQ8wgcB1\r
55         vwIazAQ0+NWbxyCDSxIRUlINjLk/DnhbbeP4dXzylR2m3be3/9eaXPzAPYPr0yOVF40+1Q1T\r
56         Jnn4JztWrNn748XxLdFndzuezrx//nmTavq5cp93O7NnpusXJnnt9eS8q+3x3vILw4plC/9e\r
57         mH8sQP2RsNfyxUvYdj2cu+7F8lgPqYVbuuzdd9tzdNwTdriwIUTQkVtCaPu0HHElluKMREMt\r
58         5qLiRABEFEly3QIAAA==\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 21:47:59 -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 \r
88 This version fixes two hard-coded paths in the tests.\r
89 \r
90  emacs/notmuch-lib.el |   92 ++++++++++++++++++++++++++++----------------------\r
91  emacs/notmuch.el     |    9 +++--\r
92  test/emacs           |   19 ++++++++---\r
93  test/emacs-show      |   26 ++++++++++----\r
94  4 files changed, 90 insertions(+), 56 deletions(-)\r
95 \r
96 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
97 index 77a591d..d78bcf8 100644\r
98 --- a/emacs/notmuch-lib.el\r
99 +++ b/emacs/notmuch-lib.el\r
100 @@ -316,23 +316,28 @@ string), a property list of face attributes, or a list of these."\r
101         (put-text-property pos next 'face (cons face cur))\r
102         (setq pos next)))))\r
103  \r
104 -(defun notmuch-pop-up-error (msg)\r
105 -  "Pop up an error buffer displaying MSG.\r
106 -\r
107 -This will accumulate error messages in the errors buffer until\r
108 -the user dismisses it."\r
109 -\r
110 -  (let ((buf (get-buffer-create "*Notmuch errors*")))\r
111 -    (with-current-buffer buf\r
112 -      (view-mode-enter nil #'kill-buffer)\r
113 -      (let ((inhibit-read-only t))\r
114 -       (goto-char (point-max))\r
115 -       (unless (bobp)\r
116 -         (insert "\n"))\r
117 -       (insert msg)\r
118 +(defun notmuch-logged-error (msg &optional extra)\r
119 +  "Log MSG and EXTRA to *Notmuch errors* and signal MSG.\r
120 +\r
121 +This logs MSG and EXTRA to the *Notmuch errors* buffer and\r
122 +signals MSG as an error.  If EXTRA is non-nil, text referring the\r
123 +user to the *Notmuch errors* buffer will be appended to the\r
124 +signaled error.  This function does not return."\r
125 +\r
126 +  (with-current-buffer (get-buffer-create "*Notmuch errors*")\r
127 +    (goto-char (point-max))\r
128 +    (unless (bobp)\r
129 +      (newline))\r
130 +    (save-excursion\r
131 +      (insert "[" (current-time-string) "]\n" msg)\r
132 +      (unless (bolp)\r
133 +       (newline))\r
134 +      (when extra\r
135 +       (insert extra)\r
136         (unless (bolp)\r
137 -         (insert "\n"))))\r
138 -    (pop-to-buffer buf)))\r
139 +         (newline)))))\r
140 +  (error "%s" (concat msg (when extra\r
141 +                           " (see *Notmuch errors* for more details)"))))\r
142  \r
143  (defun notmuch-check-async-exit-status (proc msg)\r
144    "If PROC exited abnormally, pop up an error buffer and signal an error.\r
145 @@ -363,35 +368,40 @@ contents of ERR-FILE will be included in the error message."\r
146    (cond\r
147     ((eq exit-status 0) t)\r
148     ((eq exit-status 20)\r
149 -    (notmuch-pop-up-error "Error: Version mismatch.\r
150 +    (notmuch-logged-error "notmuch CLI version mismatch\r
151  Emacs requested an older output format than supported by the notmuch CLI.\r
152 -You may need to restart Emacs or upgrade your notmuch Emacs package.")\r
153 -    (error "notmuch CLI version mismatch"))\r
154 +You may need to restart Emacs or upgrade your notmuch Emacs package."))\r
155     ((eq exit-status 21)\r
156 -    (notmuch-pop-up-error "Error: Version mismatch.\r
157 +    (notmuch-logged-error "notmuch CLI version mismatch\r
158  Emacs requested a newer output format than supported by the notmuch CLI.\r
159 -You may need to restart Emacs or upgrade your notmuch package.")\r
160 -    (error "notmuch CLI version mismatch"))\r
161 +You may need to restart Emacs or upgrade your notmuch package."))\r
162     (t\r
163 -    (notmuch-pop-up-error\r
164 -     (concat\r
165 -      (format "Error invoking notmuch.  %s exited with %s%s.\n"\r
166 -             (mapconcat #'identity command " ")\r
167 -             ;; Signal strings look like "Terminated", hence the\r
168 -             ;; colon.\r
169 -             (if (integerp exit-status) "status " "signal: ")\r
170 -             exit-status)\r
171 -      (when err-file\r
172 -       (concat "Error:\n"\r
173 -               (with-temp-buffer\r
174 -                 (insert-file-contents err-file)\r
175 -                 (if (eobp)\r
176 -                     "(no error output)\n"\r
177 -                   (buffer-string)))))\r
178 -      (when (and output (not (equal output "")))\r
179 -       (format "Output:\n%s" output))))\r
180 -    ;; Mimic `process-lines'\r
181 -    (error "%s exited with status %s" (car command) exit-status))))\r
182 +    (let* ((err (when err-file\r
183 +                 (with-temp-buffer\r
184 +                   (insert-file-contents err-file)\r
185 +                   (unless (eobp)\r
186 +                     (buffer-string)))))\r
187 +          (extra\r
188 +           (concat\r
189 +            "command: " (mapconcat #'shell-quote-argument command " ") "\n"\r
190 +            (if (integerp exit-status)\r
191 +                (format "exit status: %s\n" exit-status)\r
192 +              (format "exit signal: %s\n" exit-status))\r
193 +            (when err\r
194 +              (concat "stderr:\n" err))\r
195 +            (when output\r
196 +              (concat "stdout:\n" output)))))\r
197 +       (if err\r
198 +           ;; We have an error message straight from the CLI.\r
199 +           (notmuch-logged-error\r
200 +            (replace-regexp-in-string "\\s $" "" err) extra)\r
201 +         ;; We only have combined output from the CLI; don't inundate\r
202 +         ;; the user with it.  Mimic `process-lines'.\r
203 +         (notmuch-logged-error (format "%s exited with status %s"\r
204 +                                       (car command) exit-status)\r
205 +                               extra))\r
206 +       ;; `notmuch-logged-error' does not return.\r
207 +       ))))\r
208  \r
209  (defun notmuch-call-notmuch-json (&rest args)\r
210    "Invoke `notmuch-command' with `args' and return the parsed JSON output.\r
211 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
212 index 63387a2..c98a4fe 100644\r
213 --- a/emacs/notmuch.el\r
214 +++ b/emacs/notmuch.el\r
215 @@ -654,11 +654,14 @@ of the result."\r
216                     ;; showing the search buffer\r
217                     (when (or (= exit-status 20) (= exit-status 21))\r
218                       (kill-buffer))\r
219 -                   (condition-case nil\r
220 +                   (condition-case err\r
221                         (notmuch-check-async-exit-status proc msg)\r
222                       ;; Suppress the error signal since strange\r
223 -                     ;; things happen if a sentinel signals.\r
224 -                     (error (throw 'return nil)))\r
225 +                     ;; things happen if a sentinel signals.  Mimic\r
226 +                     ;; the top-level's handling of error messages.\r
227 +                     (error\r
228 +                      (message "%s" (second err))\r
229 +                      (throw 'return nil)))\r
230                     (if (and atbob\r
231                              (not (string= notmuch-search-target-thread "found")))\r
232                         (set 'never-found-target-thread t)))))\r
233 diff --git a/test/emacs b/test/emacs\r
234 index 6b18968..f033bdf 100755\r
235 --- a/test/emacs\r
236 +++ b/test/emacs\r
237 @@ -862,18 +862,27 @@ exit 1\r
238  EOF\r
239  chmod a+x notmuch_fail\r
240  test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
241 +              (with-current-buffer \"*Messages*\" (erase-buffer))\r
242                (notmuch-search \"tag:inbox\")\r
243                (notmuch-test-wait)\r
244 -              (test-output)\r
245 +              (with-current-buffer \"*Messages*\"\r
246 +                 (test-output \"MESSAGES\"))\r
247                (with-current-buffer \"*Notmuch errors*\"\r
248 -                 (test-output \"ERROR\")))"\r
249 -test_expect_equal "$(cat OUTPUT ERROR)" "\\r
250 +                 (test-output \"ERROR\"))\r
251 +              (test-output))"\r
252 +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
253 +test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
254  Error: Unexpected output from notmuch search:\r
255  This is output\r
256  Error: Unexpected output from notmuch search:\r
257  This is an error\r
258  End of search results.\r
259 -Error invoking notmuch.  $PWD/notmuch_fail search --format=json --format-version=1 --sort=newest-first tag:inbox exited with status 1."\r
260 -\r
261 +---\r
262 +$PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
263 +---\r
264 +[XXX]\r
265 +$PWD/notmuch_fail exited with status 1\r
266 +command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox\r
267 +exit status: 1"\r
268  \r
269  test_done\r
270 diff --git a/test/emacs-show b/test/emacs-show\r
271 index ebf530b..9f2ccb0 100755\r
272 --- a/test/emacs-show\r
273 +++ b/test/emacs-show\r
274 @@ -172,16 +172,28 @@ exit 1\r
275  EOF\r
276  chmod a+x notmuch_fail\r
277  test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
278 -              (ignore-errors (notmuch-show \"*\"))\r
279 +              (with-current-buffer \"*Messages*\" (erase-buffer))\r
280 +              (condition-case err\r
281 +                  (notmuch-show \"*\")\r
282 +                (error (message \"%s\" (second err))))\r
283                (notmuch-test-wait)\r
284 -              (test-output)\r
285 +              (with-current-buffer \"*Messages*\"\r
286 +                 (test-output \"MESSAGES\"))\r
287                (with-current-buffer \"*Notmuch errors*\"\r
288 -                 (test-output \"ERROR\")))"\r
289 -test_expect_equal "$(cat OUTPUT ERROR)" "\\r
290 -Error invoking notmuch.  $PWD/notmuch_fail show --format=json --format-version=1 --exclude=false ' * ' exited with status 1.\r
291 -Error:\r
292 +                 (test-output \"ERROR\"))\r
293 +              (test-output))"\r
294 +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
295 +test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
296 +---\r
297 +This is an error (see *Notmuch errors* for more details)\r
298 +---\r
299 +[XXX]\r
300  This is an error\r
301 -Output:\r
302 +command: $PWD/notmuch_fail show --format\\=json --format-version\\=1 --exclude\\=false \\' \\* \\'\r
303 +exit status: 1\r
304 +stderr:\r
305 +This is an error\r
306 +stdout:\r
307  This is output"\r
308  \r
309  \r
310 -- \r
311 1.7.10.4\r
312 \r