emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* bash babel code gives error
@ 2020-08-25 10:36 Colin Baxter
  2020-08-25 10:53 ` Colin Baxter
  0 siblings, 1 reply; 7+ messages in thread
From: Colin Baxter @ 2020-08-25 10:36 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I have various .tex files and an org file in the same directory. In the
org file is the following simple bash babel-code

#+begin_src bash
  sha256sum *.tex  > CHECKSUM
#+end_src

This code block used to work but no longer. It now gives the error

Error reading results: (beginning-of-buffer)

Yet the babel block

#+begin_src bash
  sha256sum -c CHECKSUM
#+end_src

works satisfactorily, and the command "sha256sum *.tex  > CHECKSUM
<RET>" works in a shell.

I'm using emacs-27.1 with Org mode version 9.3.7
(release_9.3.7-719-gcdfc40). 

Colin Baxter.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash babel code gives error
  2020-08-25 10:36 bash babel code gives error Colin Baxter
@ 2020-08-25 10:53 ` Colin Baxter
  2020-08-29 13:55   ` Kyle Meyer
  0 siblings, 1 reply; 7+ messages in thread
From: Colin Baxter @ 2020-08-25 10:53 UTC (permalink / raw)
  To: emacs-orgmode

>>>>> Colin Baxter <m43cap@yandex.com> writes:

    > Hello, I have various .tex files and an org file in the same
    > directory. In the org file is the following simple bash babel-code

    > #+begin_src bash sha256sum *.tex > CHECKSUM #+end_src


    > This code block used to work but no longer.

This is not wholly correct. It does indeed produce a checksum file
CHECKSUM, but gives the "Error reading results:
(beginning-of-buffer)". No such error was called in the past (~ a month or
so ago).

Best wishes,

Colin Baxter.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bash babel code gives error
  2020-08-25 10:53 ` Colin Baxter
@ 2020-08-29 13:55   ` Kyle Meyer
  2020-08-29 17:22     ` [PATCH] ob-core: Avoid table conversion warning for empty results Kyle Meyer
  0 siblings, 1 reply; 7+ messages in thread
From: Kyle Meyer @ 2020-08-29 13:55 UTC (permalink / raw)
  To: Colin Baxter; +Cc: emacs-orgmode

Colin Baxter writes:

>>>>>> Colin Baxter <m43cap@yandex.com> writes:
>
>     > Hello, I have various .tex files and an org file in the same
>     > directory. In the org file is the following simple bash babel-code
>
>     > #+begin_src bash sha256sum *.tex > CHECKSUM #+end_src
>
>
>     > This code block used to work but no longer.
>
> This is not wholly correct. It does indeed produce a checksum file
> CHECKSUM, but gives the "Error reading results:
> (beginning-of-buffer)". No such error was called in the past (~ a month or
> so ago).

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:
<https://orgmode.org/list/2449663.1588516024@apollo2.minshall.org>.

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ob-core: Avoid table conversion warning for empty results
  2020-08-29 13:55   ` Kyle Meyer
@ 2020-08-29 17:22     ` Kyle Meyer
  2020-08-29 19:53       ` Colin Baxter
  0 siblings, 1 reply; 7+ messages in thread
From: Kyle Meyer @ 2020-08-29 17:22 UTC (permalink / raw)
  To: Colin Baxter; +Cc: emacs-orgmode

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:
> <https://orgmode.org/list/2449663.1588516024@apollo2.minshall.org>.
>
> 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 <m43cap@yandex.com>
<https://orgmode.org/list/878se3nhbj.fsf@yandex.com>
---
 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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] ob-core: Avoid table conversion warning for empty results
  2020-08-29 17:22     ` [PATCH] ob-core: Avoid table conversion warning for empty results Kyle Meyer
@ 2020-08-29 19:53       ` Colin Baxter
  2020-08-30  6:53         ` Colin Baxter
  0 siblings, 1 reply; 7+ messages in thread
From: Colin Baxter @ 2020-08-29 19:53 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Dear Kyle,

>>>>> Kyle Meyer <kyle@kyleam.com> writes:

    > 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:
    >> <https://orgmode.org/list/2449663.1588516024@apollo2.minshall.org>.
    >> 
    >> 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.

Thank you. I'll apply the patch to my org-mode and report back.

Best wishes,

Colin Baxter.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ob-core: Avoid table conversion warning for empty results
  2020-08-29 19:53       ` Colin Baxter
@ 2020-08-30  6:53         ` Colin Baxter
  2020-09-01  4:04           ` Kyle Meyer
  0 siblings, 1 reply; 7+ messages in thread
From: Colin Baxter @ 2020-08-30  6:53 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Dear Kyle,

>>>>> Kyle Meyer <kyle@kyleam.com> writes:

    >> 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:
    >>> <https://orgmode.org/list/2449663.1588516024@apollo2.minshall.org>.
    >>> 
    >>> 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.

    > Thank you. I'll apply the patch to my org-mode and report back.

I have now applied the patch to my local org-mode git repository and it
works with no reported errors. Thanks again.

Best wishes,

Colin Baxter.


Colin Baxter
URL: http://www.Colin-Baxter.com
---------------------------------------------------------------------
GnuPG fingerprint: 68A8 799C 0230 16E7 BF68  2A27 BBFA 2492 91F5 41C8
---------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ob-core: Avoid table conversion warning for empty results
  2020-08-30  6:53         ` Colin Baxter
@ 2020-09-01  4:04           ` Kyle Meyer
  0 siblings, 0 replies; 7+ messages in thread
From: Kyle Meyer @ 2020-09-01  4:04 UTC (permalink / raw)
  To: Colin Baxter; +Cc: emacs-orgmode

Colin Baxter writes:

>     >> This patch would squelch the inappropriate warning you report
>     >> while not hiding other warnings.
>
>     > Thank you. I'll apply the patch to my org-mode and report back.
>
> I have now applied the patch to my local org-mode git repository and it
> works with no reported errors. Thanks again.

Thanks for trying it out.  Applied (7bc18ebbe).


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-01  4:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-25 10:36 bash babel code gives error Colin Baxter
2020-08-25 10:53 ` Colin Baxter
2020-08-29 13:55   ` Kyle Meyer
2020-08-29 17:22     ` [PATCH] ob-core: Avoid table conversion warning for empty results Kyle Meyer
2020-08-29 19:53       ` Colin Baxter
2020-08-30  6:53         ` Colin Baxter
2020-09-01  4:04           ` Kyle Meyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).