Re: [PATCH v3] emacs: Use the minibuffer for CLI error reporting
authorTomi Ollila <tomi.ollila@iki.fi>
Sat, 5 Jan 2013 21:33:08 +0000 (23:33 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:56 +0000 (09:52 -0800)
fc/59563151a7ceecf01558537edf2faeaa6f72ac [new file with mode: 0644]

diff --git a/fc/59563151a7ceecf01558537edf2faeaa6f72ac b/fc/59563151a7ceecf01558537edf2faeaa6f72ac
new file mode 100644 (file)
index 0000000..be49aff
--- /dev/null
@@ -0,0 +1,310 @@
+Return-Path: <tomi.ollila@iki.fi>\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 C4AD0431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Jan 2013 13:33:19 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 hvKnUtqLYREZ for <notmuch@notmuchmail.org>;\r
+       Sat,  5 Jan 2013 13:33:18 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4E268431FAE\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Jan 2013 13:33:18 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id E94AB10007D;\r
+       Sat,  5 Jan 2013 23:33:08 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3] emacs: Use the minibuffer for CLI error reporting\r
+In-Reply-To: <1357249669-9706-1-git-send-email-amdragon@mit.edu>\r
+References: <1357174222-25132-1-git-send-email-amdragon@mit.edu>\r
+       <1357249669-9706-1-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.14+236~ge6d0259 (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sat, 05 Jan 2013 23:33:08 +0200\r
+Message-ID: <m238yfjox7.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Sat, 05 Jan 2013 21:33:19 -0000\r
+\r
+On Thu, Jan 03 2013, Austin Clements <amdragon@MIT.EDU> wrote:\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
+LGTM.\r
+\r
+Mark's suggestion could go to a separate patch -- this one\r
+doesn't (seem to?) make things worse compared what it is before\r
+applying. \r
+\r
+If things are currently irritatively borken due to notmuch emitting\r
+more errors then Someone(tm) should make a proper patch following\r
+Mark's suggestion.\r
+\r
+Tomi\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r