RE: Reply all - issue
[notmuch-archives.git] / 8b / 9840727aafa948a569584dcc9d57ec8da51f3d
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 CFCB2431FB6\r
6         for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 11:48: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: -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 yO7GWXcTtdPX for <notmuch@notmuchmail.org>;\r
16         Fri, 28 Dec 2012 11:48:19 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id B859F431FAF\r
20         for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 11:48:19 -0800 (PST)\r
21 X-AuditID: 1209190f-b7f016d000000e07-51-50ddf783c5a6\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id B4.83.03591.387FDD05; Fri, 28 Dec 2012 14:48:19 -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 qBSJmHC1004154; \r
27         Fri, 28 Dec 2012 14:48:17 -0500\r
28 Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
29         [76.21.105.205]) (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 qBSJmElg023343\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 28 Dec 2012 14:48:16 -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 1Tofuf-0006mX-Dt; Fri, 28 Dec 2012 14:48:13 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH] emacs: Use the minibuffer for CLI error reporting\r
40 Date: Fri, 28 Dec 2012 14:48:08 -0500\r
41 Message-Id: <1356724088-26032-1-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 In-Reply-To: <87wqw2pcqs.fsf@zancas.localnet>\r
44 References: <87wqw2pcqs.fsf@zancas.localnet>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFjrDIsWRmVeSWpSXmKPExsUixG6nrtv8/W6AwdLDrBY3WrsZLfbs87JY\r
47         PZfH4vrNmcwOLB53T3N57Jx1l93j2apbzB5bDr1nDmCJ4rJJSc3JLEst0rdL4Mo4/Gw/W8F9\r
48         u4otE1pYGhi/G3QxcnJICJhIPLz1gxHCFpO4cG89WxcjF4eQwD5Gie/PmtlAEkICGxglZq0v\r
49         gUhcZJL49OsWC4Qzl1Gic+tasHY2AQ2JbfuXg9kiAtISO+/OZgWxmQUqJf4eWc4EYgsLOEl8\r
50         +X8OaCoHB4uAqsSWl14gYV4BB4nJt2ezQFyhKNH9bALYYk4BXYnXD6ewgJQLCehI3P3nOYGR\r
51         fwEjwypG2ZTcKt3cxMyc4tRk3eLkxLy81CJdE73czBK91JTSTYygQOOU5N/B+O2g0iFGAQ5G\r
52         JR7eE7fvBgixJpYVV+YeYpTkYFIS5d37CijEl5SfUpmRWJwRX1Sak1p8iFGCg1lJhPfLe6Ac\r
53         b0piZVVqUT5MSpqDRUmc92rKTX8hgfTEktTs1NSC1CKYrAwHh5IEb9A3oEbBotT01Iq0zJwS\r
54         hDQTByfIcB6g4aogNbzFBYm5xZnpEPlTjIpS4rwOIAkBkERGaR5cLywRvGIUB3pFmNcIpIoH\r
55         mETgul8BDWYCGmzNcwdkcEkiQkqqgXF+1axajS1u+xmVZeLWK1nbTWJrC89dd1ji8w/t4u1t\r
56         j84vmSBY58XWuyHOTyTc5LSs/5p9F8Wbp03NSf614I/TZk+ZZ91JeXl7p8sJTVSZxKCaX5fO\r
57         4GplO2P6pQubfA++O3bm8ZO0xT5p28ReitTyZOfXPVQTkPvs6Hu8vFtPwXRRwddz9UosxRmJ\r
58         hlrMRcWJAB1U6sXfAgAA\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: Fri, 28 Dec 2012 19:48:20 -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           |   11 +++---\r
90  test/emacs-show      |    6 ++--\r
91  4 files changed, 67 insertions(+), 51 deletions(-)\r
92 \r
93 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
94 index 77a591d..3baab97 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."\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 +         (basic-msg (format "%s exited with status %s"\r
185 +                            (car command) exit-status)))\r
186 +      (when (and (null err) (or (null output) (equal output "")))\r
187 +       ;; We have no details to speak of.  Mimic `process-lines'.\r
188 +       (notmuch-logged-error basic-msg))\r
189 +      (let ((extra\r
190 +            (concat\r
191 +             "Command: " (mapconcat #'shell-quote-argument command " ") "\n"\r
192 +             (if (integerp exit-status)\r
193 +                 (format "Exit status: %s\n" exit-status)\r
194 +               (format "Exit signal: %s\n" exit-status))\r
195 +             "Output:\n"\r
196 +             (if (and output (not (equal output "")))\r
197 +                 output\r
198 +               "(none)"))))\r
199 +       (if err\r
200 +           ;; We have an error message straight from the CLI.\r
201 +           (notmuch-logged-error err extra)\r
202 +         ;; We only have combined output from the CLI; don't inundate\r
203 +         ;; the user with it.\r
204 +         (notmuch-logged-error basic-msg extra)))))))\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..8e0a4fd 100755\r
232 --- a/test/emacs\r
233 +++ b/test/emacs\r
234 @@ -862,18 +862,19 @@ 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 \"*Notmuch errors*\"\r
243 -                 (test-output \"ERROR\")))"\r
244 -test_expect_equal "$(cat OUTPUT ERROR)" "\\r
245 +              (with-current-buffer \"*Messages*\"\r
246 +                 (test-output \"MESSAGES\"))\r
247 +              (test-output))"\r
248 +test_expect_equal "$(cat OUTPUT MESSAGES)" "\\r
249  Error: Unexpected output from notmuch search:\r
250  This is output\r
251  Error: Unexpected output from notmuch search:\r
252  This is an error\r
253  End of search results.\r
254 -Error invoking notmuch.  $PWD/notmuch_fail search --format=json --format-version=1 --sort=newest-first tag:inbox exited with status 1."\r
255 +$PWD/notmuch_fail exited with status 1"\r
256  \r
257  \r
258  test_done\r
259 diff --git a/test/emacs-show b/test/emacs-show\r
260 index ebf530b..ae9459d 100755\r
261 --- a/test/emacs-show\r
262 +++ b/test/emacs-show\r
263 @@ -177,10 +177,12 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
264                (test-output)\r
265                (with-current-buffer \"*Notmuch errors*\"\r
266                   (test-output \"ERROR\")))"\r
267 +sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
268  test_expect_equal "$(cat OUTPUT ERROR)" "\\r
269 -Error invoking notmuch.  $PWD/notmuch_fail show --format=json --format-version=1 --exclude=false ' * ' exited with status 1.\r
270 -Error:\r
271 +[XXX]\r
272  This is an error\r
273 +Command: $PWD/notmuch_fail show --format\\=json --format-version\\=1 --exclude\\=false \\' \\* \\'\r
274 +Exit status: 1\r
275  Output:\r
276  This is output"\r
277  \r
278 -- \r
279 1.7.10.4\r
280 \r