* [BUG] obscure error for invalid :exports
@ 2024-03-07 11:49 Max Nikulin
2024-03-08 9:46 ` Ihor Radchenko
0 siblings, 1 reply; 4+ messages in thread
From: Max Nikulin @ 2024-03-07 11:49 UTC (permalink / raw)
To: emacs-orgmode
Hi,
Trying to export (to HTML buffer)
src_elisp[:exports source]{a}
I have got an obscure error
org-export-as: Wrong type argument: char-or-string-p, nil
I believe, some meaningful error should be signaled.
I was quite surprised since the following is exported with no error
#+begin_src elisp :exports source
a
#+end_src
So source blocks are more liberal in respect to user errors.
`org-lint' warns
2 low Unknown value "source" for header ":exports"
Reproducible with Org main HEAD and 9.5.5
Of course, it should be
src_elisp[:exports code]{a}
but I was going to test org-element parser on a more tricky input and by
mistake typed wrong keyword. It took some time to figure that it is not
a parser error.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BUG] obscure error for invalid :exports
2024-03-07 11:49 [BUG] obscure error for invalid :exports Max Nikulin
@ 2024-03-08 9:46 ` Ihor Radchenko
2024-03-10 10:30 ` Max Nikulin
0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2024-03-08 9:46 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 615 bytes --]
Max Nikulin <manikulin@gmail.com> writes:
> Trying to export (to HTML buffer)
>
> src_elisp[:exports source]{a}
>
> I have got an obscure error
>
> org-export-as: Wrong type argument: char-or-string-p, nil
>
> I believe, some meaningful error should be signaled.
>
> I was quite surprised since the following is exported with no error
>
> #+begin_src elisp :exports source
> a
> #+end_src
Confirmed.
The behavior on unknown value of :exports header arg is undefined.
We may, however, show a warning in such scenario and avoid throwing
cryptic error.
See the attached tentative patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-export-Display-a-warning-when-the-value-of-expor.patch --]
[-- Type: text/x-patch, Size: 5022 bytes --]
From 8fcf787ca739008118f9834720ee56d6e190401d Mon Sep 17 00:00:00 2001
Message-ID: <8fcf787ca739008118f9834720ee56d6e190401d.1709891167.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 8 Mar 2024 12:42:33 +0300
Subject: [PATCH] org-export: Display a warning when the value of :exports
header arg is invalid
* lisp/ob-exp.el (org-babel-exp-do-export): Display warning when
:exports value is not known. Document nil return value.
(org-babel-exp-process-buffer): Do not remove code block when
`org-babel-exp-do-export' returns nil.
Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/usc9jn$g2r$1@ciao.gmane.io
---
lisp/ob-exp.el | 70 +++++++++++++++++++++++++++++++-------------------
1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index aa6091924..af726dc2c 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -218,22 +218,27 @@ (defun org-babel-exp-process-buffer ()
(goto-char begin)
(let ((replacement
(org-babel-exp-do-export info 'inline)))
- (if (equal replacement "")
- ;; Replacement code is empty: remove
- ;; inline source block, including extra
- ;; white space that might have been
- ;; created when inserting results.
- (delete-region begin
- (progn (goto-char end)
- (skip-chars-forward " \t")
- (point)))
- ;; Otherwise: remove inline source block
- ;; but preserve following white spaces.
- ;; Then insert value.
- (unless (string= replacement
- (buffer-substring begin end))
- (delete-region begin end)
- (insert replacement))))))
+ (cond
+ ((equal replacement "")
+ ;; Replacement code is empty: remove
+ ;; inline source block, including extra
+ ;; white space that might have been
+ ;; created when inserting results.
+ (delete-region begin
+ (progn (goto-char end)
+ (skip-chars-forward " \t")
+ (point))))
+ ((not replacement)
+ ;; Replacement code cannot be determined.
+ ;; Leave the code block as is.
+ (goto-char end))
+ ;; Otherwise: remove inline source block
+ ;; but preserve following white spaces.
+ ;; Then insert value.
+ ((not (string= replacement
+ (buffer-substring begin end)))
+ (delete-region begin end)
+ (insert replacement))))))
((or `babel-call `inline-babel-call)
(org-babel-exp-do-export
(or (org-babel-lob-get-info element)
@@ -249,21 +254,27 @@ (defun org-babel-exp-process-buffer ()
;; the object/element, including any extra
;; white space that might have been created
;; when including results.
- (if (equal rep "")
- (delete-region
- begin
- (progn (goto-char end)
- (if (not (eq type 'babel-call))
- (progn (skip-chars-forward " \t")
- (point))
- (skip-chars-forward " \r\t\n")
- (line-beginning-position))))
+ (cond
+ ((equal rep "")
+ (delete-region
+ begin
+ (progn (goto-char end)
+ (if (not (eq type 'babel-call))
+ (progn (skip-chars-forward " \t")
+ (point))
+ (skip-chars-forward " \r\t\n")
+ (line-beginning-position)))))
+ ((not rep)
+ ;; Replacement code cannot be determined.
+ ;; Leave the code block as is.
+ (goto-char end))
+ (t
;; Otherwise, preserve trailing
;; spaces/newlines and then, insert
;; replacement string.
(goto-char begin)
(delete-region begin end)
- (insert rep))))
+ (insert rep)))))
(`src-block
(let ((match-start (copy-marker (match-beginning 0)))
(ind (org-current-text-indentation)))
@@ -335,6 +346,8 @@ (defun org-babel-exp-do-export (info type &optional hash)
TYPE is the code block type: `block', `inline', or `lob'. HASH is the
result hash.
+Return nil when exported content cannot be determined.
+
The function respects the value of the :exports header argument."
(let ((silently (lambda () (let ((session (cdr (assq :session (nth 2 info)))))
(unless (equal "none" session)
@@ -348,7 +361,10 @@ (defun org-babel-exp-do-export (info type &optional hash)
("results" (org-babel-exp-results info type nil hash) "")
("both"
(org-babel-exp-results info type nil hash)
- (org-babel-exp-code info type)))))
+ (org-babel-exp-code info type))
+ (unknown-value
+ (warn "Unknown value of src block parameter :exports %S" unknown-value)
+ nil))))
(defcustom org-babel-exp-code-template
"#+begin_src %lang%switches%flags\n%body\n#+end_src"
--
2.43.0
[-- Attachment #3: Type: text/plain, Size: 224 bytes --]
--
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 related [flat|nested] 4+ messages in thread
* Re: [BUG] obscure error for invalid :exports
2024-03-08 9:46 ` Ihor Radchenko
@ 2024-03-10 10:30 ` Max Nikulin
2024-03-12 13:10 ` Ihor Radchenko
0 siblings, 1 reply; 4+ messages in thread
From: Max Nikulin @ 2024-03-10 10:30 UTC (permalink / raw)
To: emacs-orgmode
On 08/03/2024 16:46, Ihor Radchenko wrote:
> Max Nikulin writes:
>> Trying to export (to HTML buffer)
>> src_elisp[:exports source]{a}
>> I have got an obscure error
>> org-export-as: Wrong type argument: char-or-string-p, nil
>
> See the attached tentative patch.
Thanks, Ihor. With this patch applied, behavior is improved.
Notice however that the *Warnings* buffer may be hidden by export result
(e.g. when export to buffer is chosen in the dispatcher).
Almost certainly you already know my opinion (see example of a message
link below) that ideally export warnings should be collected with line
numbers to a buffer having compilation-minor-mode. Of course, I do not
expect that this feature will be implemented as a part of a fix for this
bug.
Max Nikulin. Re: [Syntax discussion] Should we treat src blocks without
LANG as paragraphs? Sat, 17 Dec 2022 21:47:18 +0700.
https://list.orgmode.org/tnkkpn$11am$1@ciao.gmane.io
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BUG] obscure error for invalid :exports
2024-03-10 10:30 ` Max Nikulin
@ 2024-03-12 13:10 ` Ihor Radchenko
0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2024-03-12 13:10 UTC (permalink / raw)
To: Max Nikulin; +Cc: emacs-orgmode
Max Nikulin <manikulin@gmail.com> writes:
>> See the attached tentative patch.
>
> Thanks, Ihor. With this patch applied, behavior is improved.
Applied, onto main.
Fixed.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f08174a45
> Notice however that the *Warnings* buffer may be hidden by export result
> (e.g. when export to buffer is chosen in the dispatcher).
>
> Almost certainly you already know my opinion (see example of a message
> link below) that ideally export warnings should be collected with line
> numbers to a buffer having compilation-minor-mode. Of course, I do not
> expect that this feature will be implemented as a part of a fix for this
> bug.
Yes, a better export diagnostics interface (maybe similar to org-lint)
would be nice to have.
--
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] 4+ messages in thread
end of thread, other threads:[~2024-03-12 13:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 11:49 [BUG] obscure error for invalid :exports Max Nikulin
2024-03-08 9:46 ` Ihor Radchenko
2024-03-10 10:30 ` Max Nikulin
2024-03-12 13:10 ` 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).