Re: [PATCH 1/7] emacs: Centralize notmuch command error handling
authorTomi Ollila <tomi.ollila@iki.fi>
Sat, 15 Dec 2012 16:20:30 +0000 (18:20 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:17 +0000 (09:52 -0800)
1f/1bc1b903fcc93e1965cb5990edbc85fbd8ac72 [new file with mode: 0644]

diff --git a/1f/1bc1b903fcc93e1965cb5990edbc85fbd8ac72 b/1f/1bc1b903fcc93e1965cb5990edbc85fbd8ac72
new file mode 100644 (file)
index 0000000..9acfc7a
--- /dev/null
@@ -0,0 +1,145 @@
+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 328D8431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 08:20:36 -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 VIUcT5yPPs95 for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 08:20:35 -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 650AB431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 08:20:35 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id 78A7310007E;\r
+       Sat, 15 Dec 2012 18:20:30 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/7] emacs: Centralize notmuch command error handling\r
+In-Reply-To: <1355548513-10085-2-git-send-email-amdragon@mit.edu>\r
+References: <1355548513-10085-1-git-send-email-amdragon@mit.edu>\r
+       <1355548513-10085-2-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.14+116~g29fcdb5 (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, 15 Dec 2012 18:20:30 +0200\r
+Message-ID: <m2obhvp9rl.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, 15 Dec 2012 16:20:36 -0000\r
+\r
+On Sat, Dec 15 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+\r
+> This provides library functions for unified handling of errors from\r
+> the notmuch CLI.  Follow-up patches will convert some scattered error\r
+> handling to use this and add error handling where we currently ignore\r
+> errors.\r
+> ---\r
+\r
+The series looks pretty good, some hardcoded patchs Mark noticed\r
+and it looks to me (after viewing id:8738z7hd6x.fsf@qmul.ac.uk\r
+that err -> nil could be done.\r
+\r
+Would (goto-char (point-min)) be needed before (insert msg) in\r
+this patch -- what If user has moved cursor while viewing old\r
+error messages but not pressed q (dismissed) on the buffer. \r
+Also, what about (unless (eobp) (insert "\n")) to add empty\r
+line between error messages ?\r
+\r
+Tomi\r
+\r
+>  emacs/notmuch-lib.el |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  1 file changed, 53 insertions(+)\r
+>\r
+> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+> index 9c4ee71..851098f 100644\r
+> --- a/emacs/notmuch-lib.el\r
+> +++ b/emacs/notmuch-lib.el\r
+> @@ -316,6 +316,59 @@ 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
+> +    (insert msg)\r
+> +    (unless (bolp)\r
+> +      (insert "\n"))\r
+> +    (goto-char (point-min))))\r
+> +    (pop-to-buffer buf)))\r
+> +\r
+> +(defun notmuch-check-exit-status (exit-status command &optional output err-file)\r
+> +  "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.\r
+> +\r
+> +If EXIT-STATUS is non-zero, pop up a notmuch error buffer\r
+> +describing the error and signal an Elisp error.  EXIT-STATUS must\r
+> +be a number indicating the exit status code of a process or a\r
+> +string describing the signal that terminated the process (such as\r
+> +returned by `call-process').  COMMAND must be a list giving the\r
+> +command and its arguments.  OUTPUT, if provided, is a string\r
+> +giving the output of command.  ERR-FILE, if provided, is the name\r
+> +of a file containing the error output of command.  OUTPUT and the\r
+> +contents of ERR-FILE will be included in the error message."\r
+> +\r
+> +  ;; This is implemented as a cond to make it easy to expand.\r
+> +  (cond\r
+> +   ((eq exit-status 0) t)\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
+> +\r
+>  ;; Compatibility functions for versions of emacs before emacs 23.\r
+>  ;;\r
+>  ;; Both functions here were copied from emacs 23 with the following copyright:\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r