0

Problem

In an org file, I have a source code block containing bash code that I want to run on a remote machine:

* test
  :PROPERTIES:
  :header-args:bash: :dir /ssh:skid@127.0.0.1#2221:
  :END:

  #+begin_src bash 
    whoami
  #+end_src

Placing Mark inside the block and pressing C-c C-c, I expect an output block containing the username on the remote(skid) to appear below, but I get an error: (wrong-type-argument number-or-marker-p nil)

Question

I'm a bit lost on how and why this fails, so; Any ideas on what goes wrong?

Pointers on how to interpret the trace, for a lisp noob, will be very appreaciated.

Details

SSH server and tramp seems fine on it's own

This opens the remote folder in dired mode without errors:

emacs -nw '/ssh:skid@localhost#2221:/home/skid/10.10.10.198/'

Backtrace

The backtrace (from doing M-: (setq debug-on-error t) before the above C-c C-c) is too long to include, so the first few lines are below, and the complete one is on pastebin:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  <(0 nil)
  (if (< 0 (file-attribute-size (file-attributes error-file))) (progn (save-current-buffer (set-buffer (get-buffer-create error-buffer)) (let ((pos-from-end (- (point-max) (point)))) (or (bobp) (insert "\f\n")) (format-insert-file error-file nil) (goto-char (- (point-max) pos-from-end))) (current-buffer))))
  (progn (if (< 0 (file-attribute-size (file-attributes error-file))) (progn (save-current-buffer (set-buffer (get-buffer-create error-buffer)) (let ((pos-from-end (- ... ...))) (or (bobp) (insert "\f\n")) (format-insert-file error-file nil) (goto-char (- (point-max) pos-from-end))) (current-buffer)))) (delete-file error-file))
  (if (and error-file (file-exists-p error-file)) (progn (if (< 0 (file-attribute-size (file-attributes error-file))) (progn (save-current-buffer (set-buffer (get-buffer-create error-buffer)) (let ((pos-from-end ...)) (or (bobp) (insert "\f\n")) (format-insert-file error-file nil) (goto-char (- ... pos-from-end))) (current-buffer)))) (delete-file error-file)))
  (let ((input-file (org-babel-temp-file "ob-input-")) (error-file (if error-buffer (org-babel-temp-file "ob-error-") nil)) (shell-file-name (cond ((and (not (file-remote-p default-directory)) (executable-find shell-file-name)) shell-file-name) ((file-executable-p (concat (file-remote-p default-directory) shell-file-name)) shell-file-name) ("/bin/sh"))) exit-status) (if (file-remote-p default-directory) nil (delete-file error-file)) (let ((swap (< start end))) (goto-char start) (push-mark (point) 'nomsg) (write-region start end input-file) (delete-region start end) (setq exit-status (process-file shell-file-name input-file (if error-file (list t error-file) t) nil shell-command-switch command)) (if swap (progn (exchange-point-and-mark)))) (if (and input-file (file-exists-p input-file) (not (if (boundp 'org-babel--debug-input) (progn org-babel--debug-input)))) (progn (delete-file input-file))) (if (and error-file (file-exists-p error-file)) (progn (if (< 0 (file-attribute-size (file-attributes error-file))) (progn (save-current-buffer (set-buffer (get-buffer-create error-buffer)) (let (...) (or ... ...) (format-insert-file error-file nil) (goto-char ...)) (current-buffer)))) (delete-file error-file))) exit-status)
  org-babel--shell-command-on-region(1 7 "bash" #<buffer  *Org-Babel Error*>)
  (setq exit-code (org-babel--shell-command-on-region (point-min) (point-max) cmd err-buff))
...
  org-ctrl-c-ctrl-c(nil)
  funcall-interactively(org-ctrl-c-ctrl-c nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
  command-execute(org-ctrl-c-ctrl-c)

Emacs version

GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars)

*Messages* buffer

This is what is in my *Messages*, from launching emacs, to hitting the error:

For information about GNU Emacs and the GNU system, type C-h C-a.
Starting new Ispell process /run/current-system/sw/bin/aspell with en_GB dictionary...done
Setting up indent for shell type bash
Indentation variables are now local.
Indentation setup for shell type bash
t
Setting up indent for shell type bash
Indentation variables are now local.
Indentation setup for shell type bash
executing Bash code block...
Tramp: Opening connection for skid@127.0.0.1 using ssh...
Tramp: Sending command ‘exec ssh -l skid -p 2221 -o ControlMaster=auto -o ControlPath='tramp.%C' -o ControlPersist=no -e none 127.0.0.1’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘127.0.0.1’
Tramp: Opening connection for skid@127.0.0.1 using ssh...done
Tramp: Encoding local file ‘/tmp/tramp.pKJ3ih’ using ‘base64-encode-region’...done
Tramp: Decoding remote file ‘/ssh:skid@127.0.0.1#2221:/tmp/ob-input-xciyut’ using ‘base64 -d -i >%s’...done
Tramp: Encoding local file ‘/tmp/tramp.TfMrVo’ using ‘base64-encode-region’...done
Tramp: Decoding remote file ‘/ssh:skid@127.0.0.1#2221:/tmp/ob-error-PpTmjP’ using ‘base64 -d -i >%s’...done
Tramp: Encoding local file ‘/tmp/tramp.5JTsQ8’ using ‘base64-encode-region’...done
Tramp: Decoding remote file ‘/ssh:skid@127.0.0.1#2221:/tmp/ob-input-xciyut’ using ‘base64 -d -i >%s’...done
Wrote /ssh:skid@127.0.0.1#2221:/tmp/ob-input-xciyut
Entering debugger...

Temp files

The following (empty) file is created when going through the above steps:

~$ ssh -X -p2221 skid@localhost 'ls -ltr /tmp/ob-*'
-rw-r--r-- 1 skid users 0 Feb  5 09:29 /tmp/ob-error-PpTmjP

From watch -n.1 ssh -X -p2221 skid@localhost 'ls -ltr /tmp/ob-*' it seems like nothing else is created. At least it wasn't picked up by me watching this command.

1
  1. Tramp keeps its persistent data in ~/.emacs.d/tramp. You can either remove this file prior starting Emacs, or trash its contents by M-x tramp-cleanup-all-connections any time.

  2. I've tried to reproduce your scenario. I've used my own remote machine (obviously), with a non-standard port. In order to minimize interference with other packages, I have started Emacs via emacs -Q -l org -l ob-shell. No error, it works as expected.

0

I cannot reproduce it myself any more.

After repeating this tens of times (closing emacs, restarting remote), I tried switching the remote to the default ssh port (22), and it then worked when not specifying a port. It then worked when specifying port 22 in the properties, and also when moving remote back to port 2221.

I keep the org file on git, and the remote host is a vm running nixos (https://gitlab.com/kidmose/dotfiles/-/tree/master/nixos/vms/htb-box) so i have no idea how this can happen. Does tramp store some state that can get messed up?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.