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 01800431FB6 for ; Fri, 14 Dec 2012 21:15:30 -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 GAr4StNIX5xb for ; Fri, 14 Dec 2012 21:15:29 -0800 (PST) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 82C21431FC2 for ; Fri, 14 Dec 2012 21:15:28 -0800 (PST) X-AuditID: 12074424-b7fe06d0000008f0-f7-50cc076fb88c Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id 3B.38.02288.F670CC05; Sat, 15 Dec 2012 00:15:28 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBF5FQ1F021590; Sat, 15 Dec 2012 00:15:26 -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 qBF5FOGp011443 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 15 Dec 2012 00:15:25 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1Tjk5s-0002kJ-3a; Sat, 15 Dec 2012 00:15:24 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/7] emacs: Centralize notmuch command error handling Date: Sat, 15 Dec 2012 00:15:07 -0500 Message-Id: <1355548513-10085-2-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355548513-10085-1-git-send-email-amdragon@mit.edu> References: <1355548513-10085-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrFvAfibA4M07VovVc3ksrt+cyezA 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZczoX8ZYMEWsYs2aSawNjPsEuxg5OSQETCSO /ulghbDFJC7cW8/WxcjFISSwj1HiSP88dghnA6PE2ud/mECqhAQeMUlc6fCFSMxllDjZspQN JMEmoCGxbf9yRhBbREBaYufd2WBjmQUcJT7vXwRWIyzgKnHx5CVmEJtFQFVi6ct+MJtXwAGo /hM7xBmKEt3PJoDVcwL1Lvt4jgVisYPE2Vd3WScw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiX l1qka66Xm1mil5pSuokRFEjsLio7GJsPKR1iFOBgVOLh3RFxOkCINbGsuDL3EKMkB5OSKO8t hjMBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4xbYAlfOmJFZWpRblw6SkOViUxHmvp9z0FxJI TyxJzU5NLUgtgsnKcHAoSfCyswENFSxKTU+tSMvMKUFIM3FwggznARp+lhWohre4IDG3ODMd In+KUVFKnPcJSEIAJJFRmgfXC4v0V4ziQK8I8z4CqeIBJgm47ldAg5mABsddOg4yuCQRISXV wNj+ZX2U2YdFQj2RjowGrdXJSpYvwqbPmc6l7FurczP3QGP1l01y1lYLA6bNO7dS+KzTg3/u YZWSvKlh8vz7Tr9Livd3ZjqhO22KSHqDfcq8xC3yCUebhPmdb1k31753lL0m2jD1lJjF9DCD Iymv36nXH3mus7XaZePZtX7bdx3+F2WywTZfUImlOCPRUIu5qDgRAM/mKkPPAgAA 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 05:15:30 -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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 9c4ee71..851098f 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -316,6 +316,59 @@ 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)) + (insert msg) + (unless (bolp) + (insert "\n")) + (goto-char (point-min)))) + (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