* [O] [PATCH] ob-eval: display error fix
@ 2023-01-07 13:24 Andreas Gerler
2023-01-07 21:33 ` Ruijie Yu via General discussions about Org-mode.
2023-04-14 12:44 ` Ihor Radchenko
0 siblings, 2 replies; 7+ messages in thread
From: Andreas Gerler @ 2023-01-07 13:24 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: 0001-lisp-ob-eval.el-Display-error-fix.patch --]
[-- Type: application/octet-stream, Size: 1901 bytes --]
From 923c20d153400b5278e29464d68046535f319f6b Mon Sep 17 00:00:00 2001
From: Andreas Gerler <baron@bundesbrandschatzamt.de>
Date: Sat, 7 Jan 2023 14:04:03 +0100
Subject: [PATCH] * lisp/ob-eval.el: Display error fix
* lisp/ob-eval.el: (org-babel-eval-error-notify): Display standard
error only if command exits non zero.
The problem is that sql connections might give warnings.
Now the information is available in the *Org-Babel Error* buffer
without displaying.
If you need always display toggle org-babel-eval-error-display-notify.
Signed-off-by: Andreas Gerler <baron@bundesbrandschatzamt.de>
---
lisp/ob-eval.el | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 6f6edb949..18ca48218 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -36,6 +36,12 @@
(defvar org-babel-error-buffer-name "*Org-Babel Error Output*")
(declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
+(defcustom org-babel-eval-error-display-notify nil
+ "Display org-babel-eval-errors always or only if exit code is not 0."
+ :group 'org-babel
+ :version "29.1"
+ :type 'boolean)
+
(defun org-babel-eval-error-notify (exit-code stderr)
"Open a buffer to display STDERR and a message with the value of EXIT-CODE."
(let ((buf (get-buffer-create org-babel-error-buffer-name)))
@@ -45,7 +51,11 @@
(unless (bolp) (insert "\n"))
(insert stderr)
(insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
- (display-buffer buf))
+ (if org-babel-eval-error-display-notify
+ (display-buffer buf)
+ (if (or (not (numberp exit-code))
+ (> exit-code 0))
+ (display-buffer buf))))
(message "Babel evaluation exited with code %S" exit-code))
(defun org-babel-eval (command query)
--
2.39.0
[-- Attachment #1.2: Type: text/plain, Size: 560 bytes --]
Dear all,
since commit
f7b16402e6a694d592210f766544f6114056b4b0
every sql code block is displaying the *Org-Babel Error Output* for me due to warning messages from the database.
I added a check to display the buffer only if non zero exit.
The buffer still gets written.
Additionally I added defcustom org-babel-eval-error-display-notify
If anybody is in need to display everything he can toggle it.
I signed my FSF papers in 2017 for an ob-sql patch.
so long…
Andreas Gerler
—
http://www.bundesbrandschatzamt.de/~baron
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [O] [PATCH] ob-eval: display error fix
2023-01-07 13:24 [O] [PATCH] ob-eval: display error fix Andreas Gerler
@ 2023-01-07 21:33 ` Ruijie Yu via General discussions about Org-mode.
2023-01-08 11:16 ` Andreas Gerler
2023-04-14 12:44 ` Ihor Radchenko
1 sibling, 1 reply; 7+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-01-07 21:33 UTC (permalink / raw)
To: Andreas Gerler; +Cc: emacs-orgmode
Hi Andreas,
- (display-buffer buf))
+ (if org-babel-eval-error-display-notify
+ (display-buffer buf)
+ (if (or (not (numberp exit-code))
+ (> exit-code 0))
+ (display-buffer buf))))
Quick question, does it help or hurt readability if we change this
nested `if' into a `cond' expression?
Or, alternatively, since both the outer then branch and the inner then
branch are the same expression, maybe we can just combine all three
conditions into a single `or' call?
Something like
(when (or org-babel-eval-error-display-notify
(not (numberp exit-code))
(> exit-code 0))
(display-buffer buf))
Best,
RY
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [O] [PATCH] ob-eval: display error fix
2023-01-07 21:33 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-01-08 11:16 ` Andreas Gerler
2023-01-27 1:48 ` Ruijie Yu via General discussions about Org-mode.
2023-01-27 13:10 ` Ihor Radchenko
0 siblings, 2 replies; 7+ messages in thread
From: Andreas Gerler @ 2023-01-08 11:16 UTC (permalink / raw)
To: Ruijie Yu; +Cc: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #1.2: 0001-lisp-ob-eval.el-Display-error-fix.patch --]
[-- Type: application/octet-stream, Size: 1873 bytes --]
From db391f4123a62aa214741d6b1eb43b0a1e06f1b9 Mon Sep 17 00:00:00 2001
From: Andreas Gerler <baron@bundesbrandschatzamt.de>
Date: Sat, 7 Jan 2023 14:04:03 +0100
Subject: [PATCH] * lisp/ob-eval.el: Display error fix
* lisp/ob-eval.el: (org-babel-eval-error-notify): Display standard
error only if command exits non zero.
The problem is that sql connections might give warnings.
Now the information is available in the *Org-Babel Error* buffer
without displaying.
If you need always display toggle org-babel-eval-error-display-notify.
Signed-off-by: Andreas Gerler <baron@bundesbrandschatzamt.de>
---
lisp/ob-eval.el | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el
index 6f6edb949..f4659fe96 100644
--- a/lisp/ob-eval.el
+++ b/lisp/ob-eval.el
@@ -36,6 +36,12 @@
(defvar org-babel-error-buffer-name "*Org-Babel Error Output*")
(declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
+(defcustom org-babel-eval-error-display-notify nil
+ "Display org-babel-eval-errors always or only if exit code is not 0."
+ :group 'org-babel
+ :version "29.1"
+ :type 'boolean)
+
(defun org-babel-eval-error-notify (exit-code stderr)
"Open a buffer to display STDERR and a message with the value of EXIT-CODE."
(let ((buf (get-buffer-create org-babel-error-buffer-name)))
@@ -45,7 +51,10 @@
(unless (bolp) (insert "\n"))
(insert stderr)
(insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
- (display-buffer buf))
+ (when (or org-babel-eval-error-display-notify
+ (or (not (numberp exit-code))
+ (> exit-code 0)))
+ (display-buffer buf)))
(message "Babel evaluation exited with code %S" exit-code))
(defun org-babel-eval (command query)
--
2.39.0
[-- Attachment #1.3: Type: text/plain, Size: 972 bytes --]
Hi Ruijie,
thanks for asking.
I combined them now and tested again all variants.
Andreas
> On 7. Jan 2023, at 22:33, Ruijie Yu via General discussions about Org-mode. <emacs-orgmode@gnu.org> wrote:
>
>
> Hi Andreas,
>
> - (display-buffer buf))
> + (if org-babel-eval-error-display-notify
> + (display-buffer buf)
> + (if (or (not (numberp exit-code))
> + (> exit-code 0))
> + (display-buffer buf))))
>
> Quick question, does it help or hurt readability if we change this
> nested `if' into a `cond' expression?
>
> Or, alternatively, since both the outer then branch and the inner then
> branch are the same expression, maybe we can just combine all three
> conditions into a single `or' call?
>
> Something like
>
> (when (or org-babel-eval-error-display-notify
> (not (numberp exit-code))
> (> exit-code 0))
> (display-buffer buf))
>
> Best,
>
>
> RY
>
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [O] [PATCH] ob-eval: display error fix
2023-01-08 11:16 ` Andreas Gerler
@ 2023-01-27 1:48 ` Ruijie Yu via General discussions about Org-mode.
2023-01-27 13:10 ` Ihor Radchenko
1 sibling, 0 replies; 7+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-01-27 1:48 UTC (permalink / raw)
To: Andreas Gerler; +Cc: emacs-orgmode
Ping -- I don't think anyone else has replied / reviewed this patch yet,
unless it has happened in a different thread.
Best,
RY
Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
> [[PGP Signed Part:Undecided]]
>
> [2. text/x-patch; 0001-lisp-ob-eval.el-Display-error-fix.patch]...
>
>
>
> Hi Ruijie,
>
> thanks for asking.
> I combined them now and tested again all variants.
>
> Andreas
>
>> On 7. Jan 2023, at 22:33, Ruijie Yu via General discussions about Org-mode. <emacs-orgmode@gnu.org> wrote:
>>
>>
>> Hi Andreas,
>>
>> - (display-buffer buf))
>> + (if org-babel-eval-error-display-notify
>> + (display-buffer buf)
>> + (if (or (not (numberp exit-code))
>> + (> exit-code 0))
>> + (display-buffer buf))))
>>
>> Quick question, does it help or hurt readability if we change this
>> nested `if' into a `cond' expression?
>>
>> Or, alternatively, since both the outer then branch and the inner then
>> branch are the same expression, maybe we can just combine all three
>> conditions into a single `or' call?
>>
>> Something like
>>
>> (when (or org-babel-eval-error-display-notify
>> (not (numberp exit-code))
>> (> exit-code 0))
>> (display-buffer buf))
>>
>> Best,
>>
>>
>> RY
>>
>
> [[End of PGP Signed Part]]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [O] [PATCH] ob-eval: display error fix
2023-01-08 11:16 ` Andreas Gerler
2023-01-27 1:48 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-01-27 13:10 ` Ihor Radchenko
2023-02-03 17:04 ` Andreas Gerler
1 sibling, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2023-01-27 13:10 UTC (permalink / raw)
To: Andreas Gerler; +Cc: Ruijie Yu, emacs-orgmode
Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
> +(defcustom org-babel-eval-error-display-notify nil
> + "Display org-babel-eval-errors always or only if exit code is not 0."
This docstring is confusing. What will happen if the value is nil?
non-nil? I cannot answer these questions by reading the docstring.
Also, what is "org-babel-eval-errors"? Symbol?
Finally, I do not think that "nil" is a good default here. It is better
to display warnings by default and let people disable them only
consciously, when needed. Ideally, we may allow the value to be a list
of backends where to display/not display the warnings.
> + :group 'org-babel
> + :version "29.1"
Please use :package-version instead.
And add the new customization to etc/ORG-NEWS.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [O] [PATCH] ob-eval: display error fix
2023-01-27 13:10 ` Ihor Radchenko
@ 2023-02-03 17:04 ` Andreas Gerler
0 siblings, 0 replies; 7+ messages in thread
From: Andreas Gerler @ 2023-02-03 17:04 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Ruijie Yu, emacs-orgmode
Hi Ihor,
way too busy right now.
As soon as I find some time I’ll rework that change. Might take a week or two.
so long...
Andreas Gerler
> On Jan 27, 2023, at 2:11 PM, Ihor Radchenko <yantar92@posteo.net> wrote:
>
> Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
>
>> +(defcustom org-babel-eval-error-display-notify nil
>> + "Display org-babel-eval-errors always or only if exit code is not 0."
>
> This docstring is confusing. What will happen if the value is nil?
> non-nil? I cannot answer these questions by reading the docstring.
>
> Also, what is "org-babel-eval-errors"? Symbol?
>
> Finally, I do not think that "nil" is a good default here. It is better
> to display warnings by default and let people disable them only
> consciously, when needed. Ideally, we may allow the value to be a list
> of backends where to display/not display the warnings.
>
>> + :group 'org-babel
>> + :version "29.1"
>
> Please use :package-version instead.
>
> And add the new customization to etc/ORG-NEWS.
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [O] [PATCH] ob-eval: display error fix
2023-01-07 13:24 [O] [PATCH] ob-eval: display error fix Andreas Gerler
2023-01-07 21:33 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-14 12:44 ` Ihor Radchenko
1 sibling, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2023-04-14 12:44 UTC (permalink / raw)
To: Andreas Gerler; +Cc: emacs-orgmode
Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
> * lisp/ob-eval.el: (org-babel-eval-error-notify): Display standard
> error only if command exits non zero.
>
> The problem is that sql connections might give warnings.
> Now the information is available in the *Org-Babel Error* buffer
> without displaying.
> If you need always display toggle org-babel-eval-error-display-notify.
>
I am looking at this again, and there seems to be no simple way to know
which babel backend is active when org-babel-eval is invoked.
I think that we can use a different approach to handle the problem with
sql connections:
1. Add a new optional parameter to org-babel-eval that will disable
error buffer completely or when the command exits with 0 exit code.
2. Modify org-babel-execute:sql (and maybe other backends) to pass some
header argument value to `org-babel-eval'.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-14 12:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-07 13:24 [O] [PATCH] ob-eval: display error fix Andreas Gerler
2023-01-07 21:33 ` Ruijie Yu via General discussions about Org-mode.
2023-01-08 11:16 ` Andreas Gerler
2023-01-27 1:48 ` Ruijie Yu via General discussions about Org-mode.
2023-01-27 13:10 ` Ihor Radchenko
2023-02-03 17:04 ` Andreas Gerler
2023-04-14 12:44 ` Ihor Radchenko
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).