[PATCH v3] emacs: Use the minibuffer for CLI error reporting
authorAustin Clements <amdragon@MIT.EDU>
Thu, 3 Jan 2013 21:47:49 +0000 (16:47 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:55 +0000 (09:52 -0800)
4b/b060558738d675664a5d109f62944ef614bea2 [new file with mode: 0644]

diff --git a/4b/b060558738d675664a5d109f62944ef614bea2 b/4b/b060558738d675664a5d109f62944ef614bea2
new file mode 100644 (file)
index 0000000..c1472e3
--- /dev/null
@@ -0,0 +1,312 @@
+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 880DE431FAF\r
+       for <notmuch@notmuchmail.org>; Thu,  3 Jan 2013 13:47:59 -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 NgsAuSWl8UVB for <notmuch@notmuchmail.org>;\r
+       Thu,  3 Jan 2013 13:47:58 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6A87F431FAE\r
+       for <notmuch@notmuchmail.org>; Thu,  3 Jan 2013 13:47:58 -0800 (PST)\r
+X-AuditID: 1209190d-b7efd6d000001a82-c4-50e5fc8cd7fe\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 3B.2E.06786.C8CF5E05; Thu,  3 Jan 2013 16:47:56 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r03LlsT3001005; \r
+       Thu, 3 Jan 2013 16:47:54 -0500\r
+Received: from drake.dyndns.org (a069.catapulsion.net [70.36.81.69])\r
+       (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 r03Llob5000054\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 3 Jan 2013 16:47:53 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Tqsdi-0004j1-9K; Thu, 03 Jan 2013 16:47:50 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3] emacs: Use the minibuffer for CLI error reporting\r
+Date: Thu,  3 Jan 2013 16:47:49 -0500\r
+Message-Id: <1357249669-9706-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1357174222-25132-1-git-send-email-amdragon@mit.edu>\r
+References: <1357174222-25132-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsUixG6notvz52mAwea/3BY3WrsZLfbs87JY\r
+       PZfH4vrNmcwOLB53T3N57Jx1l93j2apbzB5bDr1nDmCJ4rJJSc3JLEst0rdL4MrYMeEuc8Ee\r
+       t4pbPUINjA3mXYycHBICJhKTPs5lhrDFJC7cW88GYgsJ7GOUuHVDoouRC8hezygx/f8URghn\r
+       P5PE6V3LWSGcuYwSH4+1sYO0sAloSGzbv5wRxBYRkJbYeXc2K4jNLFApMefidCCbg0NYwFXi\r
+       2bkIEJNFQFXiwdpyEJNXwF5i+kM3iBsUJbqfTQC7gVPAUeL33hZmiHscJP49ncY4gZF/ASPD\r
+       KkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0jvdzMEr3UlNJNjKAg45Tk3cH47qDSIUYBDkYlHt4J\r
+       954GCLEmlhVX5h5ilORgUhLlrfoOFOJLyk+pzEgszogvKs1JLT7EKMHBrCTC++42UI43JbGy\r
+       KrUoHyYlzcGiJM57JeWmv5BAemJJanZqakFqEUxWhoNDSYJ30m+gRsGi1PTUirTMnBKENBMH\r
+       J8hwHqDhySA1vMUFibnFmekQ+VOMilLivEtAEgIgiYzSPLheWBJ4xSgO9IowbydIFQ8wgcB1\r
+       vwIazAQ0+NWbxyCDSxIRUlINjLk/DnhbbeP4dXzylR2m3be3/9eaXPzAPYPr0yOVF40+1Q1T\r
+       Jnn4JztWrNn748XxLdFndzuezrx//nmTavq5cp93O7NnpusXJnnt9eS8q+3x3vILw4plC/9e\r
+       mH8sQP2RsNfyxUvYdj2cu+7F8lgPqYVbuuzdd9tzdNwTdriwIUTQkVtCaPu0HHElluKMREMt\r
+       5qLiRABEFEly3QIAAA==\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: Thu, 03 Jan 2013 21:47:59 -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
+\r
+This version fixes two hard-coded paths in the tests.\r
+\r
+ emacs/notmuch-lib.el |   92 ++++++++++++++++++++++++++++----------------------\r
+ emacs/notmuch.el     |    9 +++--\r
+ test/emacs           |   19 ++++++++---\r
+ test/emacs-show      |   26 ++++++++++----\r
+ 4 files changed, 90 insertions(+), 56 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 77a591d..d78bcf8 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.  This function does not return."\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
++         (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
++           (when err\r
++             (concat "stderr:\n" err))\r
++           (when output\r
++             (concat "stdout:\n" output)))))\r
++      (if err\r
++          ;; We have an error message straight from the CLI.\r
++          (notmuch-logged-error\r
++           (replace-regexp-in-string "\\s $" "" err) extra)\r
++        ;; We only have combined output from the CLI; don't inundate\r
++        ;; the user with it.  Mimic `process-lines'.\r
++        (notmuch-logged-error (format "%s exited with status %s"\r
++                                      (car command) exit-status)\r
++                              extra))\r
++      ;; `notmuch-logged-error' does not return.\r
++      ))))\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..f033bdf 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -862,18 +862,27 @@ 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 \"*Messages*\"\r
++                (test-output \"MESSAGES\"))\r
+              (with-current-buffer \"*Notmuch errors*\"\r
+-                (test-output \"ERROR\")))"\r
+-test_expect_equal "$(cat OUTPUT ERROR)" "\\r
++                (test-output \"ERROR\"))\r
++             (test-output))"\r
++sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
++test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\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
+-\r
++---\r
++$PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
++---\r
++[XXX]\r
++$PWD/notmuch_fail exited with status 1\r
++command: $PWD/notmuch_fail search --format\=json --format-version\=1 --sort\=newest-first tag\:inbox\r
++exit status: 1"\r
\r
+ test_done\r
+diff --git a/test/emacs-show b/test/emacs-show\r
+index ebf530b..9f2ccb0 100755\r
+--- a/test/emacs-show\r
++++ b/test/emacs-show\r
+@@ -172,16 +172,28 @@ exit 1\r
+ EOF\r
+ chmod a+x notmuch_fail\r
+ test_emacs "(let ((notmuch-command \"$PWD/notmuch_fail\"))\r
+-             (ignore-errors (notmuch-show \"*\"))\r
++             (with-current-buffer \"*Messages*\" (erase-buffer))\r
++             (condition-case err\r
++                 (notmuch-show \"*\")\r
++               (error (message \"%s\" (second err))))\r
+              (notmuch-test-wait)\r
+-             (test-output)\r
++             (with-current-buffer \"*Messages*\"\r
++                (test-output \"MESSAGES\"))\r
+              (with-current-buffer \"*Notmuch errors*\"\r
+-                (test-output \"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
++                (test-output \"ERROR\"))\r
++             (test-output))"\r
++sed -i -e 's/^\[.*\]$/[XXX]/' ERROR\r
++test_expect_equal "$(cat OUTPUT; echo ---; cat MESSAGES; echo ---; cat ERROR)" "\\r
++---\r
++This is an error (see *Notmuch errors* for more details)\r
++---\r
++[XXX]\r
+ This is an error\r
+-Output:\r
++command: $PWD/notmuch_fail show --format\\=json --format-version\\=1 --exclude\\=false \\' \\* \\'\r
++exit status: 1\r
++stderr:\r
++This is an error\r
++stdout:\r
+ This is output"\r
\r
\r
+-- \r
+1.7.10.4\r
+\r