Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6BD3E431FC0 for ; Sat, 15 Dec 2012 12:04:34 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2oimcf8eyHgo for ; Sat, 15 Dec 2012 12:04:33 -0800 (PST) Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU [18.9.25.14]) by olra.theworths.org (Postfix) with ESMTP id 3CC03431FB6 for ; Sat, 15 Dec 2012 12:04:33 -0800 (PST) X-AuditID: 1209190e-b7f516d0000008e4-e2-50ccd7d0b881 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id 4E.06.02276.0D7DCC05; Sat, 15 Dec 2012 15:04:32 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBFK4Vlj013137; Sat, 15 Dec 2012 15:04:31 -0500 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBFK4Sp7025681 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 15 Dec 2012 15:04:30 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1TjxyG-0007sR-IF; Sat, 15 Dec 2012 15:04:28 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 1/7] emacs: Centralize notmuch command error handling Date: Sat, 15 Dec 2012 15:04:14 -0500 Message-Id: <1355601860-30121-2-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355601860-30121-1-git-send-email-amdragon@mit.edu> References: <1355601860-30121-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrnvh+pkAg95OJYvVc3ksrt+cyWzx ZuU8Vgdmj52z7rJ7HP66kMXj2apbzAHMUVw2Kak5mWWpRfp2CVwZl48/ZCvYJVYxZ9U5xgbG W4JdjBwcEgImEh+eCnUxcgKZYhIX7q1n62Lk4hAS2Mco0fuhmxnC2cAose30bFYI5xGTxKLW 7YwQzlxGiUc7X7KB9LMJaEhs27+cEcQWEZCW2HkXpIOTg1kgTmLLlP9gcWEBD4lDJy8wgdgs AqoSTRM2gtm8Ag4SZ3sPskHcoSjR/WwCmM0p4CgxcfIusBohoJrbC+YwTWDkX8DIsIpRNiW3 Sjc3MTOnODVZtzg5MS8vtUjXWC83s0QvNaV0EyMouDgl+XYwfj2odIhRgINRiYd3R8TpACHW xLLiytxDjJIcTEqivBmXzwQI8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuFNmg+U401JrKxKLcqH SUlzsCiJ815JuekvJJCeWJKanZpakFoEk5Xh4FCS4BUCRpGQYFFqempFWmZOCUKaiYMTZDgP 0HAOkBre4oLE3OLMdIj8KUZFKXFeO5CEAEgiozQPrhcW/a8YxYFeEeb9cA2oigeYOOC6XwEN ZgIavNwGbHBJIkJKqoHR3Ujeepppw6aZ0dVdiYuWisiyPip9LzCTp0h50vrtGXvajOfvqfy8 0NTvwaNFJg8WGs1x+lE7b52xoLstS5uZosWbCdO4PC7XzmXTlvd5tPiBWfeCsD8OG9I/9PV+ yfm1d8XESeoaBwRfPUhqyzj64MJJidpZSV+bW14b33q7Jmvuhm8PjdeJKLEUZyQaajEXFScC AKWLEf/ZAgAA Cc: tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Dec 2012 20:04:34 -0000 This provides library functions for unified handling of errors from the notmuch CLI. Follow-up patches will convert some scattered error handling to use this and add error handling where we currently ignore errors. --- emacs/notmuch-lib.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 9c4ee71..f757ce7 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -316,6 +316,61 @@ string), a property list of face attributes, or a list of these." (put-text-property pos next 'face (cons face cur)) (setq pos next))))) +(defun notmuch-pop-up-error (msg) + "Pop up an error buffer displaying MSG. + +This will accumulate error messages in the errors buffer until +the user dismisses it." + + (let ((buf (get-buffer-create "*Notmuch errors*"))) + (with-current-buffer buf + (view-mode-enter nil #'kill-buffer) + (let ((inhibit-read-only t)) + (goto-char (point-max)) + (unless (bobp) + (insert "\n")) + (insert msg) + (unless (bolp) + (insert "\n")))) + (pop-to-buffer buf))) + +(defun notmuch-check-exit-status (exit-status command &optional output err-file) + "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error. + +If EXIT-STATUS is non-zero, pop up a notmuch error buffer +describing the error and signal an Elisp error. EXIT-STATUS must +be a number indicating the exit status code of a process or a +string describing the signal that terminated the process (such as +returned by `call-process'). COMMAND must be a list giving the +command and its arguments. OUTPUT, if provided, is a string +giving the output of command. ERR-FILE, if provided, is the name +of a file containing the error output of command. OUTPUT and the +contents of ERR-FILE will be included in the error message." + + ;; This is implemented as a cond to make it easy to expand. + (cond + ((eq exit-status 0) t) + (t + (notmuch-pop-up-error + (concat + (format "Error invoking notmuch. %s exited with %s%s.\n" + (mapconcat #'identity command " ") + ;; Signal strings look like "Terminated", hence the + ;; colon. + (if (integerp exit-status) "status " "signal: ") + exit-status) + (when err-file + (concat "Error:\n" + (with-temp-buffer + (insert-file-contents err-file) + (if (eobp) + "(no error output)\n" + (buffer-string))))) + (when (and output (not (equal output ""))) + (format "Output:\n%s" output)))) + ;; Mimic `process-lines' + (error "%s exited with status %s" (car command) exit-status)))) + ;; Compatibility functions for versions of emacs before emacs 23. ;; ;; Both functions here were copied from emacs 23 with the following copyright: -- 1.7.10.4