emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel-tangle throws an error when :tangle is not set
@ 2021-03-27 17:12 Rodrigo Morales
  0 siblings, 0 replies; only message in thread
From: Rodrigo Morales @ 2021-03-27 17:12 UTC (permalink / raw)
  To: emacs-orgmode


* System information

Emacs version: GNU Emacs 27.2

Org Mode version: Org mode version 9.4.4 (release_9.4.4 @ /usr/share/emacs/27.2/lisp/org/)

Operating system: Arch Linux

* The issue

In a freshly started Emacs (i.e. Emacs when it has been started through =emacs -Q=), the value of the variable =org-babel-default-header-args= is 

#+begin_src emacs-lisp
((:session . "none")
 (:results . "replace")
 (:exports . "code")
 (:cache . "no")
 (:noweb . "no")
 (:hlines . "no")
 (:tangle . "no")))
#+end_src

If we delete the cons cell whose car is =:tangle=. That is, if we evaluate the following expression,

#+name: value-for-variable
#+begin_src emacs-lisp :results silent
(setq org-babel-default-header-args
      '((:session . "none")
	(:results . "replace")
	(:exports . "code")
	(:cache . "no")
	(:noweb . "no")
	(:hlines . "no")))
#+end_src

then the function =org-babel-tangle= will throw the following error =Wrong type argument: stringp, nil= with the following backtrace

#+begin_example
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-name-directory(nil)
  org-babel-tangle-single-block(1)
  org-babel-tangle-collect-blocks(nil nil)
  org-babel-tangle(nil)
  funcall-interactively(org-babel-tangle nil)
  call-interactively(org-babel-tangle nil nil)
  command-execute(org-babel-tangle)
#+end_example

* Reproducing the issue

You can reproduce this issue by

1. Start Emacs by executing =emacs -Q=.
2. Save the content of this message to a file whose extension is =org=.
3. Evaluate the expression shown above from the code block named =value-for-variable=.
4. Execute =org-babel-tangle= be it interactively or through =eval-expression=.

* Additional information

This error can be avoided by explicitly having a =:tangle= header argument in each code block.

* Personal thoughts

I had to spend more than 90 minutes looking for the expression in my configuration that was causing this error. I think that either

+ showing a error message expressing that the =:tangle= header argument is not set for some code blocks when =org-babel-tangle= is executed.
+ explicitly stating in the documentation that the =:tangle= header argument is necessary for some functions to correctly work (e.g. =org-babel-tangle=)

could help other users to find this root cause so that they don't spend the time I spent looking for the issue.

-- 
Greetings,
Rodrigo Morales.

IRC: rdrg109 (freenode)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-27 17:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27 17:12 org-babel-tangle throws an error when :tangle is not set Rodrigo Morales

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).