meedstrom / org-node

A notetaking system like Roam using Emacs Org-mode
GNU General Public License v3.0
155 stars 5 forks source link

Error when tramp buffers are opened #46

Closed walseb closed 1 month ago

walseb commented 1 month ago

Hello!

Thanks so much for this amazing package!

Whenever I have any org tramp buffers open and do a scan, it fails with this error:

Debugger entered--Lisp error: (file-missing "Setting current directory" "No such file or directory" "/su:root@thinkpad-t480:/home/admin/Notes/")
  make-process(:name "org-node-0" :noquery t :stderr #<buffer  *org-node*> :command ("/nix/store/hh01zj389h6shkz2slnw77vf4xi8hmxq-emacs-git-20240915.0/bin/emacs" "--quick" "--batch" "--eval" "(setq gc-cons-threshold 4660672571)" "--eval" "(setq i 0)" "--eval" "(setq temporary-file-directory \"/tmp/\")" "--load" "/home/admin/.emacs.d/eln-cache/31.0.50-f54e4d53/org-node-parser-01324455-2750b62d.eln" "--funcall" "org-node-parser--collect-dangerously") :sentinel #f(lambda (_process _event) [(n-jobs 7) (finalizer org-node--finalize-full)] (org-node--handle-finished-job n-jobs finalizer)))
  (cons (make-process :name (format "org-node-%d" i) :noquery t :stderr (get-buffer-create org-node--stderr-name) :command (list (file-name-concat invocation-directory invocation-name) "--quick" "--batch" "--eval" (format "(setq gc-cons-threshold %d)" gc-ultra) "--eval" (format "(setq i %d)" i) "--eval" (format "(setq temporary-file-directory \"%s\")" temporary-file-directory) "--load" compiled-lib "--funcall" "org-node-parser--collect-dangerously") :sentinel #'(lambda (_process _event) (org-node--handle-finished-job n-jobs finalizer))) org-node--processes)
  (setq org-node--processes (cons (make-process :name (format "org-node-%d" i) :noquery t :stderr (get-buffer-create org-node--stderr-name) :command (list (file-name-concat invocation-directory invocation-name) "--quick" "--batch" "--eval" (format "(setq gc-cons-threshold %d)" gc-ultra) "--eval" (format "(setq i %d)" i) "--eval" (format "(setq temporary-file-directory \"%s\")" temporary-file-directory) "--load" compiled-lib "--funcall" "org-node-parser--collect-dangerously") :sentinel #'(lambda (_process _event) (org-node--handle-finished-job n-jobs finalizer))) org-node--processes))
  (let ((i counter)) (delete-file (org-node-parser--tmpfile "results-%d.eld" i)) (let ((temp-file (org-node-parser--tmpfile "file-list-%d.eld" i)) (temp-buffer (generate-new-buffer " *temp file*" t))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (let ((write-region-inhibit-fsync nil) (print-length nil)) (insert (prin1-to-string ...)))) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (setq org-node--processes (cons (make-process :name (format "org-node-%d" i) :noquery t :stderr (get-buffer-create org-node--stderr-name) :command (list (file-name-concat invocation-directory invocation-name) "--quick" "--batch" "--eval" (format "(setq gc-cons-threshold %d)" gc-ultra) "--eval" (format "(setq i %d)" i) "--eval" (format "(setq temporary-file-directory \"%s\")" temporary-file-directory) "--load" compiled-lib "--funcall" "org-node-parser--collect-dangerously") :sentinel #'(lambda (_process _event) (org-node--handle-finished-job n-jobs finalizer))) org-node--processes)))
  (while (< counter upper-bound) (let ((i counter)) (delete-file (org-node-parser--tmpfile "results-%d.eld" i)) (let ((temp-file (org-node-parser--tmpfile "file-list-%d.eld" i)) (temp-buffer (generate-new-buffer " *temp file*" t))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (let (... ...) (insert ...))) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (setq org-node--processes (cons (make-process :name (format "org-node-%d" i) :noquery t :stderr (get-buffer-create org-node--stderr-name) :command (list (file-name-concat invocation-directory invocation-name) "--quick" "--batch" "--eval" (format "(setq gc-cons-threshold %d)" gc-ultra) "--eval" (format "(setq i %d)" i) "--eval" (format "(setq temporary-file-directory \"%s\")" temporary-file-directory) "--load" compiled-lib "--funcall" "org-node-parser--collect-dangerously") :sentinel #'(lambda (_process _event) (org-node--handle-finished-job n-jobs finalizer))) org-node--processes))) (setq counter (1+ counter)))
  (let ((upper-bound n-jobs) (counter 0)) (while (< counter upper-bound) (let ((i counter)) (delete-file (org-node-parser--tmpfile "results-%d.eld" i)) (let ((temp-file (org-node-parser--tmpfile "file-list-%d.eld" i)) (temp-buffer (generate-new-buffer " *temp file*" t))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (let ... ...)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (setq org-node--processes (cons (make-process :name (format "org-node-%d" i) :noquery t :stderr (get-buffer-create org-node--stderr-name) :command (list (file-name-concat invocation-directory invocation-name) "--quick" "--batch" "--eval" (format "(setq gc-cons-threshold %d)" gc-ultra) "--eval" (format "(setq i %d)" i) "--eval" (format "(setq temporary-file-directory \"%s\")" temporary-file-directory) "--load" compiled-lib "--funcall" "org-node-parser--collect-dangerously") :sentinel #'(lambda ... ...)) org-node--processes))) (setq counter (1+ counter))))
  (let* ((file-lists (org-node--split-into-n-sublists files org-node-perf-max-jobs)) (n-jobs (length file-lists)) (gc-ultra (let ((default-directory invocation-directory)) (/ (* 1000 (car (memory-info))) n-jobs)))) (let ((upper-bound n-jobs) (counter 0)) (while (< counter upper-bound) (let ((i counter)) (delete-file (org-node-parser--tmpfile "results-%d.eld" i)) (let ((temp-file (org-node-parser--tmpfile "file-list-%d.eld" i)) (temp-buffer (generate-new-buffer " *temp file*" t))) (unwind-protect (prog1 (save-current-buffer ... ...) (save-current-buffer ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (setq org-node--processes (cons (make-process :name (format "org-node-%d" i) :noquery t :stderr (get-buffer-create org-node--stderr-name) :command (list ... "--quick" "--batch" "--eval" ... "--eval" ... "--eval" ... "--load" compiled-lib "--funcall" "org-node-parser--collect-dangerously") :sentinel #'...) org-node--processes))) (setq counter (1+ counter)))))
  (if org-node--debug (progn (delete-file (org-node-parser--tmpfile "results-0.eld")) (let ((print-length nil)) (write-region (prin1-to-string files) nil (org-node-parser--tmpfile "file-list-0.eld"))) (setq i 0) (setq org-node-parser--result:found-links nil) (setq org-node-parser--result:problems nil) (setq org-node-parser--result:paths-types nil) (if (and (boundp 'editorconfig-mode) editorconfig-mode) (progn (message "Maybe disable editorconfig-mode while debugging"))) (setq org-node--first-init nil) (load-file compiled-lib) (garbage-collect) (setq org-node--time-at-scan-begin (current-time)) (save-current-buffer (set-buffer (get-buffer-create "*org-node debug*")) (if (eq 'show org-node--debug) (progn (pop-to-buffer (current-buffer)))) (erase-buffer) (org-node-parser--collect-dangerously) (org-node--handle-finished-job 1 finalizer))) (let* ((file-lists (org-node--split-into-n-sublists files org-node-perf-max-jobs)) (n-jobs (length file-lists)) (gc-ultra (let ((default-directory invocation-directory)) (/ (* 1000 (car ...)) n-jobs)))) (let ((upper-bound n-jobs) (counter 0)) (while (< counter upper-bound) (let ((i counter)) (delete-file (org-node-parser--tmpfile "results-%d.eld" i)) (let ((temp-file ...) (temp-buffer ...)) (unwind-protect (prog1 ... ...) (and ... ...))) (setq org-node--processes (cons (make-process :name ... :noquery t :stderr ... :command ... :sentinel ...) org-node--processes))) (setq counter (1+ counter))))))
  (let ((compiled-lib (org-node--ensure-compiled-lib)) (file-name-handler-alist nil) (coding-system-for-read org-node-perf-assume-coding-system) (coding-system-for-write org-node-perf-assume-coding-system)) (if org-node--debug (progn (garbage-collect))) (setq org-node--time-at-scan-begin (current-time)) (setq org-node--done-ctr 0) (if (-any-p #'process-live-p org-node--processes) (progn (mapc #'delete-process org-node--processes) (message "org-node processes alive, bug report would be appreciated"))) (setq org-node--processes nil) (save-current-buffer (set-buffer (get-buffer-create org-node--stderr-name)) (erase-buffer)) (let ((temp-file (org-node-parser--tmpfile "work-variables.eld")) (temp-buffer (generate-new-buffer " *temp file*" t))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (let ((standard-output ...) (print-length nil) (print-level nil)) (prin1 (append org-node-inject-variables ...)))) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (if org-node--debug (progn (delete-file (org-node-parser--tmpfile "results-0.eld")) (let ((print-length nil)) (write-region (prin1-to-string files) nil (org-node-parser--tmpfile "file-list-0.eld"))) (setq i 0) (setq org-node-parser--result:found-links nil) (setq org-node-parser--result:problems nil) (setq org-node-parser--result:paths-types nil) (if (and (boundp 'editorconfig-mode) editorconfig-mode) (progn (message "Maybe disable editorconfig-mode while debugging"))) (setq org-node--first-init nil) (load-file compiled-lib) (garbage-collect) (setq org-node--time-at-scan-begin (current-time)) (save-current-buffer (set-buffer (get-buffer-create "*org-node debug*")) (if (eq 'show org-node--debug) (progn (pop-to-buffer (current-buffer)))) (erase-buffer) (org-node-parser--collect-dangerously) (org-node--handle-finished-job 1 finalizer))) (let* ((file-lists (org-node--split-into-n-sublists files org-node-perf-max-jobs)) (n-jobs (length file-lists)) (gc-ultra (let ((default-directory invocation-directory)) (/ (* 1000 ...) n-jobs)))) (let ((upper-bound n-jobs) (counter 0)) (while (< counter upper-bound) (let ((i counter)) (delete-file (org-node-parser--tmpfile "results-%d.eld" i)) (let (... ...) (unwind-protect ... ...)) (setq org-node--processes (cons ... org-node--processes))) (setq counter (1+ counter)))))))
  org-node--scan((...) org-node--finalize-full)
  (progn (setq org-node--full-scan-requested nil) (org-node--scan (org-node-list-files) #'org-node--finalize-full) (if org-node--file-queue (progn (setq must-retry t))))
  (if org-node--full-scan-requested (progn (setq org-node--full-scan-requested nil) (org-node--scan (org-node-list-files) #'org-node--finalize-full) (if org-node--file-queue (progn (setq must-retry t)))) (org-node--scan org-node--file-queue #'org-node--finalize-modified) (setq org-node--file-queue nil))
  (if (seq-some #'process-live-p org-node--processes) (progn (if org-node--wait-start nil (setq org-node--wait-start (current-time))) (if (> (float-time (time-since org-node--wait-start)) 30) (progn (setq org-node--wait-start nil) (message "org-node: processes worked longer than 30 sec, killing") (catch 'done4 (while t (let* (...) (if old-process ... ...))))) (setq must-retry t))) (setq org-node--wait-start nil) (if org-node--full-scan-requested (progn (setq org-node--full-scan-requested nil) (org-node--scan (org-node-list-files) #'org-node--finalize-full) (if org-node--file-queue (progn (setq must-retry t)))) (org-node--scan org-node--file-queue #'org-node--finalize-modified) (setq org-node--file-queue nil)))
  (let (must-retry) (if (seq-some #'process-live-p org-node--processes) (progn (if org-node--wait-start nil (setq org-node--wait-start (current-time))) (if (> (float-time (time-since org-node--wait-start)) 30) (progn (setq org-node--wait-start nil) (message "org-node: processes worked longer than 30 sec, killing") (catch 'done4 (while t (let* ... ...)))) (setq must-retry t))) (setq org-node--wait-start nil) (if org-node--full-scan-requested (progn (setq org-node--full-scan-requested nil) (org-node--scan (org-node-list-files) #'org-node--finalize-full) (if org-node--file-queue (progn (setq must-retry t)))) (org-node--scan org-node--file-queue #'org-node--finalize-modified) (setq org-node--file-queue nil))) (if must-retry (progn (cancel-timer org-node--retry-timer) (setq org-node--retry-timer (run-with-timer 1 nil #'org-node--try-launch-scan)))))
  org-node--try-launch-scan(t)
  org-node--scan-all()
  (progn (org-node--scan-all))
  (if force (progn (org-node--scan-all)))
  org-node-cache-ensure(nil t)
  org-node-reset()

The reason it errors is probably due to the batch instances of Emacs not having those tramp connections established.

I tried patching it so that it removes any tramp files but it doesn't do anything because of some reason:

(advice-add 'org-node--scan :around
            (defun my/org-node-scan-patch (orig-func files finalizer)
              (let ((files-prime (-remove #'tramp-tramp-file-p files)))
                (funcall orig-func files-prime finalizer))))

Also, it's strange that it checks all org files open also. I would prefer if it just checked what's in the org-id-locations.

Thoughts?

Thanks so much!

meedstrom commented 1 month ago

Thanks for the backtrace! I suspect it's actually got to do with make-process doing something to set current directory - and file-name-handler-alist is temporarily nil, so Emacs temporarily doesn't know what a /su:... path means. I'll look into it.

meedstrom commented 1 month ago

Does that change help? https://github.com/meedstrom/org-node/commit/d763e608843ef75f27b1be249b8fa1790ee3407b

meedstrom commented 1 month ago

Also, it's strange that it checks all org files open also. I would prefer if it just checked what's in the org-id-locations.

Hm, yes, it checks every Org file that you save, after save. Perhaps it could ignore tramp paths. That's a good idea as long as tramp is not supported.

Other than that, an org-node-reset only checks the files output by org-node-list-files, which is org-id-locations plus what's under your org-node-extra-id-dirs.

meedstrom commented 1 month ago

Reproduced the issue, and the fix worked on my end.

walseb commented 1 month ago

Thanks so much for fixing this! I will try it out later today and reopen the issue if it's not fixed.