[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / d2 / d3a9f15ca927e94f11c000765724cf0a1a8388
1 Return-Path: <m.walters@qmul.ac.uk>\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 78E08431FB6\r
6         for <notmuch@notmuchmail.org>; Sat, 29 Dec 2012 10:00:20 -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: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id Qk6IuyG2vCsj for <notmuch@notmuchmail.org>;\r
17         Sat, 29 Dec 2012 10:00:19 -0800 (PST)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id A3780431FAF\r
22         for <notmuch@notmuchmail.org>; Sat, 29 Dec 2012 10:00:18 -0800 (PST)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1Tp0hj-00031n-B4; Sat, 29 Dec 2012 18:00:15 +0000\r
27 Received: from 94.197.9.104.threembb.co.uk ([94.197.9.104] helo=localhost)\r
28         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
29         (envelope-from <m.walters@qmul.ac.uk>)\r
30         id 1Tp0hc-00021Y-9f; Sat, 29 Dec 2012 18:00:15 +0000\r
31 From: Mark Walters <markwalters1009@gmail.com>\r
32 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
33 Subject: Re: [PATCH] emacs: Use the minibuffer for CLI error reporting\r
34 In-Reply-To: <1356724088-26032-1-git-send-email-amdragon@mit.edu>\r
35 References: <87wqw2pcqs.fsf@zancas.localnet>\r
36         <1356724088-26032-1-git-send-email-amdragon@mit.edu>\r
37 User-Agent: Notmuch/0.14+236~g1d0044f (http://notmuchmail.org) Emacs/23.4.1\r
38         (x86_64-pc-linux-gnu)\r
39 Date: Sat, 29 Dec 2012 18:00:06 +0000\r
40 Message-ID: <87r4m820yh.fsf@qmul.ac.uk>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=us-ascii\r
43 X-Sender-Host-Address: 94.197.9.104\r
44 X-QM-SPAM-Info: Sender has good ham record.  :)\r
45 X-QM-Body-MD5: b41ddfec0532531c5a658b929c786d0a (of first 20000 bytes)\r
46 X-SpamAssassin-Score: -1.8\r
47 X-SpamAssassin-SpamBar: -\r
48 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
49         determine if it is\r
50         spam. We require at least 5.0 points to mark a message as spam.\r
51         This message scored -1.8 points.\r
52         Summary of the scoring: \r
53         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
54         *      medium trust\r
55         *      [138.37.6.40 listed in list.dnswl.org]\r
56         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
57         provider *      (markwalters1009[at]gmail.com)\r
58         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
59         *      domain\r
60         *  0.5 AWL AWL: From: address is in the auto white-list\r
61 X-QM-Scan-Virus: ClamAV says the message is clean\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Sat, 29 Dec 2012 18:00:20 -0000\r
75 \r
76 On Fri, 28 Dec 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
77 > We recently switched to popping up a buffer to report CLI errors, but\r
78 > this was too intrusive, especially for transient errors and especially\r
79 > since we made fewer things ignore errors.  This patch changes this to\r
80 > display a basic error message in the minibuffer (using Emacs' usual\r
81 > error handling path) and, if there are additional details, to log\r
82 > these to a separate error buffer and reference the error buffer from\r
83 > the minibuffer message.  This is more in line with how Emacs typically\r
84 > handles errors, but makes the details available to the user without\r
85 > flooding them with the details.\r
86 >\r
87 > Given this split, we pare down the basic message and make it more\r
88 > user-friendly, and also make the verbose message even more detailed\r
89 > (and more debugging-oriented).\r
90 \r
91 I like this approach but have some queries below.\r
92 \r
93 > ---\r
94 >  emacs/notmuch-lib.el |   92 ++++++++++++++++++++++++++++----------------------\r
95 >  emacs/notmuch.el     |    9 +++--\r
96 >  test/emacs           |   11 +++---\r
97 >  test/emacs-show      |    6 ++--\r
98 >  4 files changed, 67 insertions(+), 51 deletions(-)\r
99 >\r
100 > diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
101 > index 77a591d..3baab97 100644\r
102 > --- a/emacs/notmuch-lib.el\r
103 > +++ b/emacs/notmuch-lib.el\r
104 > @@ -316,23 +316,28 @@ string), a property list of face attributes, or a list of these."\r
105 >       (put-text-property pos next 'face (cons face cur))\r
106 >       (setq pos next)))))\r
107 >  \r
108 > -(defun notmuch-pop-up-error (msg)\r
109 > -  "Pop up an error buffer displaying MSG.\r
110 > -\r
111 > -This will accumulate error messages in the errors buffer until\r
112 > -the user dismisses it."\r
113 > -\r
114 > -  (let ((buf (get-buffer-create "*Notmuch errors*")))\r
115 > -    (with-current-buffer buf\r
116 > -      (view-mode-enter nil #'kill-buffer)\r
117 > -      (let ((inhibit-read-only t))\r
118 > -     (goto-char (point-max))\r
119 > -     (unless (bobp)\r
120 > -       (insert "\n"))\r
121 > -     (insert msg)\r
122 > +(defun notmuch-logged-error (msg &optional extra)\r
123 > +  "Log MSG and EXTRA to *Notmuch errors* and signal MSG.\r
124 > +\r
125 > +This logs MSG and EXTRA to the *Notmuch errors* buffer and\r
126 > +signals MSG as an error.  If EXTRA is non-nil, text referring the\r
127 > +user to the *Notmuch errors* buffer will be appended to the\r
128 > +signaled error."\r
129 \r
130 It might be worth commenting that since this signals an error it does\r
131 not "return"; I found the code in notmuch-check-exit-status rather\r
132 confusing until I realised that.\r
133 \r
134 > +\r
135 > +  (with-current-buffer (get-buffer-create "*Notmuch errors*")\r
136 > +    (goto-char (point-max))\r
137 > +    (unless (bobp)\r
138 > +      (newline))\r
139 > +    (save-excursion\r
140 > +      (insert "[" (current-time-string) "]\n" msg)\r
141 > +      (unless (bolp)\r
142 > +     (newline))\r
143 > +      (when extra\r
144 > +     (insert extra)\r
145 >       (unless (bolp)\r
146 > -       (insert "\n"))))\r
147 > -    (pop-to-buffer buf)))\r
148 > +       (newline)))))\r
149 > +  (error "%s" (concat msg (when extra\r
150 > +                         " (see *Notmuch errors* for more details)"))))\r
151 >  \r
152 >  (defun notmuch-check-async-exit-status (proc msg)\r
153 >    "If PROC exited abnormally, pop up an error buffer and signal an error.\r
154 > @@ -363,35 +368,40 @@ contents of ERR-FILE will be included in the error message."\r
155 >    (cond\r
156 >     ((eq exit-status 0) t)\r
157 >     ((eq exit-status 20)\r
158 > -    (notmuch-pop-up-error "Error: Version mismatch.\r
159 > +    (notmuch-logged-error "notmuch CLI version mismatch\r
160 >  Emacs requested an older output format than supported by the notmuch CLI.\r
161 > -You may need to restart Emacs or upgrade your notmuch Emacs package.")\r
162 > -    (error "notmuch CLI version mismatch"))\r
163 > +You may need to restart Emacs or upgrade your notmuch Emacs package."))\r
164 >     ((eq exit-status 21)\r
165 > -    (notmuch-pop-up-error "Error: Version mismatch.\r
166 > +    (notmuch-logged-error "notmuch CLI version mismatch\r
167 >  Emacs requested a newer output format than supported by the notmuch CLI.\r
168 > -You may need to restart Emacs or upgrade your notmuch package.")\r
169 > -    (error "notmuch CLI version mismatch"))\r
170 > +You may need to restart Emacs or upgrade your notmuch package."))\r
171 >     (t\r
172 > -    (notmuch-pop-up-error\r
173 > -     (concat\r
174 > -      (format "Error invoking notmuch.  %s exited with %s%s.\n"\r
175 > -           (mapconcat #'identity command " ")\r
176 > -           ;; Signal strings look like "Terminated", hence the\r
177 > -           ;; colon.\r
178 > -           (if (integerp exit-status) "status " "signal: ")\r
179 > -           exit-status)\r
180 > -      (when err-file\r
181 > -     (concat "Error:\n"\r
182 > -             (with-temp-buffer\r
183 > -               (insert-file-contents err-file)\r
184 > -               (if (eobp)\r
185 > -                   "(no error output)\n"\r
186 > -                 (buffer-string)))))\r
187 > -      (when (and output (not (equal output "")))\r
188 > -     (format "Output:\n%s" output))))\r
189 > -    ;; Mimic `process-lines'\r
190 > -    (error "%s exited with status %s" (car command) exit-status))))\r
191 > +    (let ((err (when err-file\r
192 > +              (with-temp-buffer\r
193 > +                (insert-file-contents err-file)\r
194 > +                (unless (eobp)\r
195 > +                  (buffer-string)))))\r
196 > +       (basic-msg (format "%s exited with status %s"\r
197 > +                          (car command) exit-status)))\r
198 > +      (when (and (null err) (or (null output) (equal output "")))\r
199 > +     ;; We have no details to speak of.  Mimic `process-lines'.\r
200 \r
201 This means that if err and output are null we give a minimal error message and we\r
202 don't log the command line that fails. Perhaps the `when' clause could\r
203 be omitted so we get the extra information from below?\r
204 \r
205 > +     (notmuch-logged-error basic-msg))\r
206 > +      (let ((extra\r
207 > +          (concat\r
208 > +           "Command: " (mapconcat #'shell-quote-argument command " ") "\n"\r
209 > +           (if (integerp exit-status)\r
210 > +               (format "Exit status: %s\n" exit-status)\r
211 > +             (format "Exit signal: %s\n" exit-status))\r
212 > +           "Output:\n"\r
213 > +           (if (and output (not (equal output "")))\r
214 > +               output\r
215 > +             "(none)"))))\r
216 > +     (if err\r
217 > +         ;; We have an error message straight from the CLI.\r
218 > +         (notmuch-logged-error err extra)\r
219 > +       ;; We only have combined output from the CLI; don't inundate\r
220 > +       ;; the user with it.\r
221 > +       (notmuch-logged-error basic-msg extra)))))))\r
222 \r
223 Also, depending how the above gets changed, would it be worth pulling the let\r
224 clause before the cond clause, and subsuming some of the when/if/else\r
225 logic into the cond? This has the nice side effect that the reader\r
226 expects cond clauses to stop after the first match so the fact that\r
227 notmuch-check-exit-status signals an error would not matter when reading\r
228 this code.\r
229 \r
230 I think a command line would be useful in almost all cases (in the error\r
231 buffer). If you decide to always supply that then your error message\r
232 might want tweaking as it would always have extra information in the\r
233 error buffer.\r
234 \r
235 Finally, and this is only a thought, I wonder if the mechanism can be\r
236 tweaked to provide debug information along these lines for all notmuch\r
237 commands whether or not they succeed: something like if\r
238 notmuch-debug-commands is set or there is an error? \r
239 \r
240 Incidentally do you have good ways to test this code (ie see what it\r
241 does in each case)? My hackish experiments suggested the async errors\r
242 were less useful than the sync ones but maybe that is just an inherent\r
243 limitation of the emacs async mechanisms.\r
244 \r
245 \r
246 Best wishes\r
247 \r
248 Mark\r
249 \r
250 \r
251 \r
252 \r
253 \r
254 \r
255 >  \r
256 >  (defun notmuch-call-notmuch-json (&rest args)\r
257 >    "Invoke `notmuch-command' with `args' and return the parsed JSON output.\r
258 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
259 > index 63387a2..c98a4fe 100644\r
260 > --- a/emacs/notmuch.el\r
261 > +++ b/emacs/notmuch.el\r
262 > @@ -654,11 +654,14 @@ of the result."\r
263 >                   ;; showing the search buffer\r
264 >                   (when (or (= exit-status 20) (= exit-status 21))\r
265 >                     (kill-buffer))\r
266 > -                 (condition-case nil\r
267 > +                 (condition-case err\r
268 >                       (notmuch-check-async-exit-status proc msg)\r
269 >                     ;; Suppress the error signal since strange\r
270 > -                   ;; things happen if a sentinel signals.\r
271 > -                   (error (throw 'return nil)))\r
272 > +                   ;; things happen if a sentinel signals.  Mimic\r
273 > +                   ;; the top-level's handling of error messages.\r
274 > +                   (error\r
275 > +                    (message "%s" (second err))\r
276 > +                    (throw 'return nil)))\r
277 >                   (if (and atbob\r
278 >                            (not (string= notmuch-search-target-thread "found")))\r
279 >                       (set 'never-found-target-thread t)))))\r
280 > diff --git a/test/emacs b/test/emacs\r
281 > index 6b18968..8e0a4fd 100755\r
282 > --- a/test/emacs\r
283 > +++ b/test/emacs\r
284 > @@ -862,18 +862,19 @@ exit 1\r
285 >  EOF\r
286 >  chmod a+x notmuch_fail\r
287 >  test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
288 > +            (with-current-buffer \"*Messages*\" (erase-buffer))\r
289 >              (notmuch-search \"tag:inbox\")\r
290 >              (notmuch-test-wait)\r
291 > -            (test-output)\r
292 > -            (with-current-buffer \"*Notmuch errors*\"\r
293 > -               (test-output \"ERROR\")))"\r
294 > -test_expect_equal "$(cat OUTPUT ERROR)" "\\r
295 > +            (with-current-buffer \"*Messages*\"\r
296 > +               (test-output \"MESSAGES\"))\r
297 > +            (test-output))"\r
298 > +test_expect_equal "$(cat OUTPUT MESSAGES)" "\\r
299 >  Error: Unexpected output from notmuch search:\r
300 >  This is output\r
301 >  Error: Unexpected output from notmuch search:\r
302 >  This is an error\r
303 >  End of search results.\r
304 > -Error invoking notmuch.  $PWD/notmuch_fail search --format=json --format-version=1 --sort=newest-first tag:inbox exited with status 1."\r
305 > +$PWD/notmuch_fail exited with status 1"\r
306 >  \r
307 >  \r
308 >  test_done\r
309 > diff --git a/test/emacs-show b/test/emacs-show\r
310 > index ebf530b..ae9459d 100755\r
311 > --- a/test/emacs-show\r
312 > +++ b/test/emacs-show\r
313 > @@ -177,10 +177,12 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
314 >              (test-output)\r
315 >              (with-current-buffer \"*Notmuch errors*\"\r
316 >                 (test-output \"ERROR\")))"\r
317 > +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
318 >  test_expect_equal "$(cat OUTPUT ERROR)" "\\r
319 > -Error invoking notmuch.  $PWD/notmuch_fail show --format=json --format-version=1 --exclude=false ' * ' exited with status 1.\r
320 > -Error:\r
321 > +[XXX]\r
322 >  This is an error\r
323 > +Command: $PWD/notmuch_fail show --format\\=json --format-version\\=1 --exclude\\=false \\' \\* \\'\r
324 > +Exit status: 1\r
325 >  Output:\r
326 >  This is output"\r
327 >  \r
328 > -- \r
329 > 1.7.10.4\r