From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gNrlFAmPSl92TQAA0tVLHw (envelope-from ) for ; Sat, 29 Aug 2020 17:23:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KO2iEAmPSl8/LQAAB5/wlQ (envelope-from ) for ; Sat, 29 Aug 2020 17:23:21 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7CB9D94053D for ; Sat, 29 Aug 2020 17:23:20 +0000 (UTC) Received: from localhost ([::1]:51188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kC4ZT-0002JW-3W for larch@yhetil.org; Sat, 29 Aug 2020 13:23:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kC4Z7-0002JG-2z for emacs-orgmode@gnu.org; Sat, 29 Aug 2020 13:22:57 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:53807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kC4Z3-0004hT-HN for emacs-orgmode@gnu.org; Sat, 29 Aug 2020 13:22:56 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 3F5A38452F; Sat, 29 Aug 2020 13:22:50 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:date:message-id:mime-version:content-type; s=sasl; bh=vOaC4JsLNb5qcLo9XJ7OSpW9uD0=; b=Ju9Oiq/JatGeR6xHyO7B OYO9K+PVa2YJ5jpDANgoEd6H01OjnKwv+QQD9FgY3Ghk2pWZMb/Tx22HP2mxTOxc hTR+lj4LHwCCUjZtzfi3Qo162vxfBsO05TZnqdWieqxOTwkPjI3bOsT/9pTlBeDh FQch24AL8dWHytAaBlg4vA4= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 374998452E; Sat, 29 Aug 2020 13:22:50 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:date:message-id:mime-version:content-type; s=mesmtp; bh=ScoXrQNLTc/Y1qD+pz6pKUIGel6cwfw//UzLM67sM9I=; b=ebfFO5UsVVHicDk6vsvB5ObwwnI6swObbTRHAiEx/uOSD3Il9i71CBR0pmRhtyTDe8hc+US8cHW8MgdZTQhl8WZVp1Dcg5AX6nDkibLVk1Fhrja2IOcikhrDuaYl1mWnBomuUU8RjEG70w8RE3Q8wihroxrWCWUQ0CFCwqZD/qE= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id AF9AB8452A; Sat, 29 Aug 2020 13:22:49 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Colin Baxter Subject: [PATCH] ob-core: Avoid table conversion warning for empty results In-Reply-To: <87h7slsgit.fsf@kyleam.com> Date: Sat, 29 Aug 2020 13:22:48 -0400 Message-ID: <878sdxtlhz.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 434D5FA4-EA1C-11EA-9CA7-2F5D23BA3BAF-24757444!pb-smtp2.pobox.com Received-SPF: pass client-ip=64.147.108.71; envelope-from=kyle@kyleam.com; helo=pb-smtp2.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/29 13:22:51 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=Ju9Oiq/J; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=ebfFO5Us; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.21 X-TUID: fgmP25EPwtlM Kyle Meyer writes: > Thanks for reporting. The _display_ of this warning starts with my > 14878f3f9 (ob-core: Display warning on failure to read results, > 2020-05-21). Here's the associated thread on the mailing list: > . > > On that commit's parent (eecee2266), the error is triggered and caught > in the same way, but "Error reading results: (beginning-of-buffer)" is > buried in the messages buffer rather than being displayed as a warning. > > I'll need to take a closer look at what's going on, though I wouldn't be > surprised if it's been around for a long time. This patch would squelch the inappropriate warning you report while not hiding other warnings. -- >8 -- Subject: [PATCH] ob-core: Avoid table conversion warning for empty results * lisp/ob-core.el (org-babel-import-elisp-from-file): Don't try to convert empty file to a table. * testing/lisp/test-ob.el (test-ob/import-elisp-from-file): Add tests. If org-babel-import-elisp-from-file is called with an empty file (which many ob- libraries do when there are no results), feeding that to org-table-import leads to a beginning-of-buffer error. Before 14878f3f9 (ob-core: Display warning on failure to read results, 2020-05-21), this error was hard to notice because, after catching it, it was reported as a quickly buried message. After that commit, it is displayed as a warning, which is not appropriate for the common and unproblematic case of empty results. Avoid the warning by only doing the table conversion if the file has content. Another option would be to do the table conversion but add a beginning-of-buffer arm to the surrounding condition-case. However, that risks swallowing other sources of that error. Reported-by: Colin Baxter --- lisp/ob-core.el | 17 +++++++++++------ testing/lisp/test-ob.el | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 578622232..5b79919e8 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -3003,13 +3003,18 @@ (defun org-babel-import-elisp-from-file (file-name &optional separator) (with-temp-buffer (condition-case err (progn - (org-table-import file-name separator) + (insert-file-contents file-name) (delete-file file-name) - (delq nil - (mapcar (lambda (row) - (and (not (eq row 'hline)) - (mapcar #'org-babel-string-read row))) - (org-table-to-lisp)))) + (let ((pmax (point-max))) + ;; If the file was empty, don't bother trying to + ;; convert the table. + (when (> pmax 1) + (org-table-convert-region (point-min) pmax separator) + (delq nil + (mapcar (lambda (row) + (and (not (eq row 'hline)) + (mapcar #'org-babel-string-read row))) + (org-table-to-lisp)))))) (error (display-warning 'org-babel (format "Error reading results: %S" err) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index afaf13555..580cd7d89 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -2252,6 +2252,34 @@ (ert-deftest test-ob/string-to-number () (should (= 0.1 (org-babel--string-to-number "0.1"))) (should (= 1.0 (org-babel--string-to-number "1.0")))) +(ert-deftest test-ob/import-elisp-from-file () + "Test `org-babel-import-elisp-from-file'." + (should + (equal + (org-test-with-temp-text-in-file "line 1\nline 2\n" + (cl-letf (((symbol-function 'display-warning) + (lambda (&rest _) (error "No warnings should occur")) + (org-table-convert-region-max-lines 2))) + (org-babel-import-elisp-from-file (buffer-file-name)))) + '(("line" 1) + ("line" 2)))) + ;; If an error occurs during table conversion, it is shown with + ;; `display-warning' rather than as a message to make sure the + ;; caller sees it. + (should-error + (org-test-with-temp-text-in-file "line 1\nline 2\n" + (cl-letf (((symbol-function 'display-warning) + (lambda (&rest _) (error "Warning should be displayed"))) + (org-table-convert-region-max-lines 1)) + (org-babel-import-elisp-from-file (buffer-file-name))))) + ;; But an empty file (as is the case when there are no execution + ;; results) does not trigger a warning. + (should-not + (org-test-with-temp-text-in-file "" + (cl-letf (((symbol-function 'display-warning) + (lambda (&rest _) (error "No warnings should occur")))) + (org-babel-import-elisp-from-file (buffer-file-name)))))) + (provide 'test-ob) ;;; test-ob ends here base-commit: e8ebf5d6c93aaa8f343f897f890deb1304ca9d4b -- 2.28.0