--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id CFCB2431FB6\r
+ for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 11:48:20 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id yO7GWXcTtdPX for <notmuch@notmuchmail.org>;\r
+ Fri, 28 Dec 2012 11:48:19 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+ [18.9.25.15])\r
+ by olra.theworths.org (Postfix) with ESMTP id B859F431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 28 Dec 2012 11:48:19 -0800 (PST)\r
+X-AuditID: 1209190f-b7f016d000000e07-51-50ddf783c5a6\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id B4.83.03591.387FDD05; Fri, 28 Dec 2012 14:48:19 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBSJmHC1004154; \r
+ Fri, 28 Dec 2012 14:48:17 -0500\r
+Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
+ [76.21.105.205]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBSJmElg023343\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Fri, 28 Dec 2012 14:48:16 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Tofuf-0006mX-Dt; Fri, 28 Dec 2012 14:48:13 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: Use the minibuffer for CLI error reporting\r
+Date: Fri, 28 Dec 2012 14:48:08 -0500\r
+Message-Id: <1356724088-26032-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <87wqw2pcqs.fsf@zancas.localnet>\r
+References: <87wqw2pcqs.fsf@zancas.localnet>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrDIsWRmVeSWpSXmKPExsUixG6nrtv8/W6AwdLDrBY3WrsZLfbs87JY\r
+ PZfH4vrNmcwOLB53T3N57Jx1l93j2apbzB5bDr1nDmCJ4rJJSc3JLEst0rdL4Mo4/Gw/W8F9\r
+ u4otE1pYGhi/G3QxcnJICJhIPLz1gxHCFpO4cG89WxcjF4eQwD5Gie/PmtlAEkICGxglZq0v\r
+ gUhcZJL49OsWC4Qzl1Gic+tasHY2AQ2JbfuXg9kiAtISO+/OZgWxmQUqJf4eWc4EYgsLOEl8\r
+ +X8OaCoHB4uAqsSWl14gYV4BB4nJt2ezQFyhKNH9bALYYk4BXYnXD6ewgJQLCehI3P3nOYGR\r
+ fwEjwypG2ZTcKt3cxMyc4tRk3eLkxLy81CJdE73czBK91JTSTYygQOOU5N/B+O2g0iFGAQ5G\r
+ JR7eE7fvBgixJpYVV+YeYpTkYFIS5d37CijEl5SfUpmRWJwRX1Sak1p8iFGCg1lJhPfLe6Ac\r
+ b0piZVVqUT5MSpqDRUmc92rKTX8hgfTEktTs1NSC1CKYrAwHh5IEb9A3oEbBotT01Iq0zJwS\r
+ hDQTByfIcB6g4aogNbzFBYm5xZnpEPlTjIpS4rwOIAkBkERGaR5cLywRvGIUB3pFmNcIpIoH\r
+ mETgul8BDWYCGmzNcwdkcEkiQkqqgXF+1axajS1u+xmVZeLWK1nbTWJrC89dd1ji8w/t4u1t\r
+ j84vmSBY58XWuyHOTyTc5LSs/5p9F8Wbp03NSf614I/TZk+ZZ91JeXl7p8sJTVSZxKCaX5fO\r
+ 4GplO2P6pQubfA++O3bm8ZO0xT5p28ReitTyZOfXPVQTkPvs6Hu8vFtPwXRRwddz9UosxRmJ\r
+ hlrMRcWJAB1U6sXfAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 28 Dec 2012 19:48:20 -0000\r
+\r
+We recently switched to popping up a buffer to report CLI errors, but\r
+this was too intrusive, especially for transient errors and especially\r
+since we made fewer things ignore errors. This patch changes this to\r
+display a basic error message in the minibuffer (using Emacs' usual\r
+error handling path) and, if there are additional details, to log\r
+these to a separate error buffer and reference the error buffer from\r
+the minibuffer message. This is more in line with how Emacs typically\r
+handles errors, but makes the details available to the user without\r
+flooding them with the details.\r
+\r
+Given this split, we pare down the basic message and make it more\r
+user-friendly, and also make the verbose message even more detailed\r
+(and more debugging-oriented).\r
+---\r
+ emacs/notmuch-lib.el | 92 ++++++++++++++++++++++++++++----------------------\r
+ emacs/notmuch.el | 9 +++--\r
+ test/emacs | 11 +++---\r
+ test/emacs-show | 6 ++--\r
+ 4 files changed, 67 insertions(+), 51 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 77a591d..3baab97 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -316,23 +316,28 @@ string), a property list of face attributes, or a list of these."\r
+ (put-text-property pos next 'face (cons face cur))\r
+ (setq pos next)))))\r
+ \r
+-(defun notmuch-pop-up-error (msg)\r
+- "Pop up an error buffer displaying MSG.\r
+-\r
+-This will accumulate error messages in the errors buffer until\r
+-the user dismisses it."\r
+-\r
+- (let ((buf (get-buffer-create "*Notmuch errors*")))\r
+- (with-current-buffer buf\r
+- (view-mode-enter nil #'kill-buffer)\r
+- (let ((inhibit-read-only t))\r
+- (goto-char (point-max))\r
+- (unless (bobp)\r
+- (insert "\n"))\r
+- (insert msg)\r
++(defun notmuch-logged-error (msg &optional extra)\r
++ "Log MSG and EXTRA to *Notmuch errors* and signal MSG.\r
++\r
++This logs MSG and EXTRA to the *Notmuch errors* buffer and\r
++signals MSG as an error. If EXTRA is non-nil, text referring the\r
++user to the *Notmuch errors* buffer will be appended to the\r
++signaled error."\r
++\r
++ (with-current-buffer (get-buffer-create "*Notmuch errors*")\r
++ (goto-char (point-max))\r
++ (unless (bobp)\r
++ (newline))\r
++ (save-excursion\r
++ (insert "[" (current-time-string) "]\n" msg)\r
++ (unless (bolp)\r
++ (newline))\r
++ (when extra\r
++ (insert extra)\r
+ (unless (bolp)\r
+- (insert "\n"))))\r
+- (pop-to-buffer buf)))\r
++ (newline)))))\r
++ (error "%s" (concat msg (when extra\r
++ " (see *Notmuch errors* for more details)"))))\r
+ \r
+ (defun notmuch-check-async-exit-status (proc msg)\r
+ "If PROC exited abnormally, pop up an error buffer and signal an error.\r
+@@ -363,35 +368,40 @@ contents of ERR-FILE will be included in the error message."\r
+ (cond\r
+ ((eq exit-status 0) t)\r
+ ((eq exit-status 20)\r
+- (notmuch-pop-up-error "Error: Version mismatch.\r
++ (notmuch-logged-error "notmuch CLI version mismatch\r
+ Emacs requested an older output format than supported by the notmuch CLI.\r
+-You may need to restart Emacs or upgrade your notmuch Emacs package.")\r
+- (error "notmuch CLI version mismatch"))\r
++You may need to restart Emacs or upgrade your notmuch Emacs package."))\r
+ ((eq exit-status 21)\r
+- (notmuch-pop-up-error "Error: Version mismatch.\r
++ (notmuch-logged-error "notmuch CLI version mismatch\r
+ Emacs requested a newer output format than supported by the notmuch CLI.\r
+-You may need to restart Emacs or upgrade your notmuch package.")\r
+- (error "notmuch CLI version mismatch"))\r
++You may need to restart Emacs or upgrade your notmuch package."))\r
+ (t\r
+- (notmuch-pop-up-error\r
+- (concat\r
+- (format "Error invoking notmuch. %s exited with %s%s.\n"\r
+- (mapconcat #'identity command " ")\r
+- ;; Signal strings look like "Terminated", hence the\r
+- ;; colon.\r
+- (if (integerp exit-status) "status " "signal: ")\r
+- exit-status)\r
+- (when err-file\r
+- (concat "Error:\n"\r
+- (with-temp-buffer\r
+- (insert-file-contents err-file)\r
+- (if (eobp)\r
+- "(no error output)\n"\r
+- (buffer-string)))))\r
+- (when (and output (not (equal output "")))\r
+- (format "Output:\n%s" output))))\r
+- ;; Mimic `process-lines'\r
+- (error "%s exited with status %s" (car command) exit-status))))\r
++ (let ((err (when err-file\r
++ (with-temp-buffer\r
++ (insert-file-contents err-file)\r
++ (unless (eobp)\r
++ (buffer-string)))))\r
++ (basic-msg (format "%s exited with status %s"\r
++ (car command) exit-status)))\r
++ (when (and (null err) (or (null output) (equal output "")))\r
++ ;; We have no details to speak of. Mimic `process-lines'.\r
++ (notmuch-logged-error basic-msg))\r
++ (let ((extra\r
++ (concat\r
++ "Command: " (mapconcat #'shell-quote-argument command " ") "\n"\r
++ (if (integerp exit-status)\r
++ (format "Exit status: %s\n" exit-status)\r
++ (format "Exit signal: %s\n" exit-status))\r
++ "Output:\n"\r
++ (if (and output (not (equal output "")))\r
++ output\r
++ "(none)"))))\r
++ (if err\r
++ ;; We have an error message straight from the CLI.\r
++ (notmuch-logged-error err extra)\r
++ ;; We only have combined output from the CLI; don't inundate\r
++ ;; the user with it.\r
++ (notmuch-logged-error basic-msg extra)))))))\r
+ \r
+ (defun notmuch-call-notmuch-json (&rest args)\r
+ "Invoke `notmuch-command' with `args' and return the parsed JSON output.\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 63387a2..c98a4fe 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -654,11 +654,14 @@ of the result."\r
+ ;; showing the search buffer\r
+ (when (or (= exit-status 20) (= exit-status 21))\r
+ (kill-buffer))\r
+- (condition-case nil\r
++ (condition-case err\r
+ (notmuch-check-async-exit-status proc msg)\r
+ ;; Suppress the error signal since strange\r
+- ;; things happen if a sentinel signals.\r
+- (error (throw 'return nil)))\r
++ ;; things happen if a sentinel signals. Mimic\r
++ ;; the top-level's handling of error messages.\r
++ (error\r
++ (message "%s" (second err))\r
++ (throw 'return nil)))\r
+ (if (and atbob\r
+ (not (string= notmuch-search-target-thread "found")))\r
+ (set 'never-found-target-thread t)))))\r
+diff --git a/test/emacs b/test/emacs\r
+index 6b18968..8e0a4fd 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -862,18 +862,19 @@ exit 1\r
+ EOF\r
+ chmod a+x notmuch_fail\r
+ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
++ (with-current-buffer \"*Messages*\" (erase-buffer))\r
+ (notmuch-search \"tag:inbox\")\r
+ (notmuch-test-wait)\r
+- (test-output)\r
+- (with-current-buffer \"*Notmuch errors*\"\r
+- (test-output \"ERROR\")))"\r
+-test_expect_equal "$(cat OUTPUT ERROR)" "\\r
++ (with-current-buffer \"*Messages*\"\r
++ (test-output \"MESSAGES\"))\r
++ (test-output))"\r
++test_expect_equal "$(cat OUTPUT MESSAGES)" "\\r
+ Error: Unexpected output from notmuch search:\r
+ This is output\r
+ Error: Unexpected output from notmuch search:\r
+ This is an error\r
+ End of search results.\r
+-Error invoking notmuch. $PWD/notmuch_fail search --format=json --format-version=1 --sort=newest-first tag:inbox exited with status 1."\r
++$PWD/notmuch_fail exited with status 1"\r
+ \r
+ \r
+ test_done\r
+diff --git a/test/emacs-show b/test/emacs-show\r
+index ebf530b..ae9459d 100755\r
+--- a/test/emacs-show\r
++++ b/test/emacs-show\r
+@@ -177,10 +177,12 @@ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
+ (test-output)\r
+ (with-current-buffer \"*Notmuch errors*\"\r
+ (test-output \"ERROR\")))"\r
++sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
+ test_expect_equal "$(cat OUTPUT ERROR)" "\\r
+-Error invoking notmuch. $PWD/notmuch_fail show --format=json --format-version=1 --exclude=false ' * ' exited with status 1.\r
+-Error:\r
++[XXX]\r
+ This is an error\r
++Command: $PWD/notmuch_fail show --format\\=json --format-version\\=1 --exclude\\=false \\' \\* \\'\r
++Exit status: 1\r
+ Output:\r
+ This is output"\r
+ \r
+-- \r
+1.7.10.4\r
+\r