org-roam-ui
org-roam-ui copied to clipboard
[BUG] Org-roam-ui doesn't show the node's text if in a .dir-locals.el location
I am trying to have more than one org-roam directory using a .dir-local file in such directory. When I define (setq org-roam-directory (file-truename "~/repos/org-roam")) in my config, and I'm in that set of roam files, org-roam-ui works great and as expected. And so does org-roam-graph.
If I then switch to my .dir-local set of roam files, the graph displays, I can jump to a node in emacs, but I get displayed:
<!DOCTYPE html> <html><head> <title>500 Internal Error</title> </head><body> <h1>500 Internal Error</h1> <p>Internal error when handling this request.</p> <pre>error: (wrong-type-argument number-or-marker-p nil) </pre> </body></html>
I don't know if this means anything, but org-roam-graph also does not work in the .dir-local set. It generates a correct .dot file in /tmp, but then does not successfully generate the .svg file as expected.
Here's what's in the .dir-locals.el file:
((nil . ((org-roam-directory . "[correct absolute path to separate dir]")
(org-roam-db-location . "[correct absolute path to separate dir]/org-roam.db"))))
I had the same issue. And I find that it's better to use relative path in .dir-locals.el as:
((nil . ((org-roam-directory . ".")
(org-roam-db-location . "./org-roam.db"))))
Besides, after changing roam directory, try to refresh both roam directory and reload emacs, i.e. use SPC n r s and SPC h r r in doom-emacs.
I'll try that out later today; I though org-roam-directory had to be absolute paths though.
Unfortunately that doesn't work.
same problem here
exactly the same problem here +1

org-roam support .dir-locals.el without any problem Version Info: org-roam: 2.2.2 org-roam-ui: 20220225.2151
same here, where .dir-locals.el is
((nil . ((eval . (setq-local
org-roam-directory (expand-file-name "notes/net" (locate-dominating-file
default-directory ".dir-locals.el"))))
(eval . (setq-local
org-roam-db-location (expand-file-name "org-roam.db"
org-roam-directory))))))
httpd server reports:
(request
(date "Sun, 10 Jul 2022 21:04:28 GMT")
(address "127.0.0.1")
(get "/node/5e80de0b-1b4a-4510-9829-be201f4b7f03")
(headers
("GET" "/node/5e80de0b-1b4a-4510-9829-be201f4b7f03" "HTTP/1.1")
("Host" "localhost:35901")
("User-Agent" "Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0")
("Accept" "*/*")
("Accept-Language" "en-US,en;q=0.5")
("Accept-Encoding" "gzip, deflate, br")
("Referer" "http://localhost:35901/")
("Connection" "keep-alive")
("Sec-Fetch-Dest" "empty")
("Sec-Fetch-Mode" "cors")
("Sec-Fetch-Site" "same-origin")
("Content" "")))
(error 500
(wrong-type-argument number-or-marker-p nil))
my settings:
;; ---(org-roam)------------------------------------------------------------------------
;; @see: https://systemcrafters.net/build-a-second-brain-in-emacs/5-org-roam-hacks/
(use-package org-roam
:ensure t
:init
(setq org-roam-v2-ack t)
:custom
(org-roam-directory (file-truename "~/Dropbox/Local/data/org/net"))
;;(org-roam-completion-everywhere t)
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n g" . org-roam-graph)
("C-c n i" . org-roam-node-insert)
("C-c n c" . org-roam-capture)
;; Dailies
("C-c n j" . org-roam-dailies-capture-today)
;; :map org-mode-map
;; ("C-M-i" . completion-at-point)
;; :map org-roam-dailies-map
;; ("Y" . org-roam-dailies-capture-yesterday)
;; ("T" . org-roam-dailies-capture-tomorrow)
)
;; :bind-keymap
;; ("C-c n d" . org-roam-dailies-map)
:config
;; (require 'org-roam-dailies) ;; Ensure the keymap is available
;; If you're using a vertical completion framework, you might want a more informative completion interface
(setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
(setq org-roam-capture-templates
'(
("d" "default" plain
"%?"
:if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t)
("s" "system" plain
"* Info\n\n- Module: ${title}\n- OS: %^{os}\n- Layer: %^{layer}\n- Zone: %^{zone}\n- Version: %^{version}\n\n* Related:\n\n- \n\n* Bindings:\n\n- %?\n\n* References:\n\n- "
:if-new (file+head "system/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t)
("v" "devel" plain
"* Info\n\n- Module: ${title}\n- Lang: %^{lang}\n- Frame: %^{frame}\n- Context: %^{context}\n- Version: %^{version}\n\n* Related:\n\n- \n\n* Bindings:\n\n- %?\n\n* References:\n\n- "
:if-new (file+head "devel/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t)
("b" "book notes" plain
"\n* Source\n\nAuthor: %^{Author}\nTitle: ${title}\nYear: %^{Year}\n\n* Summary\n\n%?"
:if-new (file+head "refs/%<%Y%m%d%H%M%S>-b-${slug}.org" "#+title: ${title}\n")
:unnarrowed t)
("l" "Online link" plain
"\n* Source\n\nTitle: ${title}\nURL: %^{URL}\n\n* Summary\n\n%?"
:if-new (file+head "refs/%<%Y%m%d%H%M%S>-l-${slug}.org" "#+title: ${title}\n")
:unnarrowed t)
))
(org-roam-db-autosync-mode)
;; If using org-roam-protocol
(require 'org-roam-protocol))
;; ---(http server)------------------------------------------------------------------------
(use-package websocket
:after org-roam
;; :straight (:host github :repo "ahyatt/emacs-websocket" :branch "main")
)
(use-package simple-httpd
:after org-roam
)
;; ---(org-roam-ui)------------------------------------------------------------------------
(use-package org-roam-ui
:ensure t
;; :straight
;; (:host github :repo "org-roam/org-roam-ui" :branch "main" :files ("*.el" "out"))
:quelpa (org-roam-ui :fetcher github :repo "org-roam/org-roam-ui")
:after org-roam
;; ;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have
;; ;; a hookable mode anymore, you're advised to pick something yourself
;; ;; if you don't care about startup time, use
;; :hook (after-init . org-roam-ui-mode)
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t))
That's what is causing that?! I'll have to debug this soon.
I got similar error as reported by @hute37. The error does not show in the httpd buffer when org-roam-ui-open is executed. The error only shows when clicking on a specific node to view the detailed notes.
The graph/linkages are correctly generated, but not the content in the .org file.
(start "Mon Aug 22 00:32:14 2022")
(connection "127.0.0.1")
(request
(date "Mon, 22 Aug 2022 05:32:32 GMT")
(address "127.0.0.1")
(get "/node/3843340f-2573-483b-ba88-30f233653ee7")
(headers
("GET" "/node/3843340f-2573-483b-ba88-30f233653ee7" "HTTP/1.1")
("Host" "localhost:35901")
("Connection" "keep-alive")
("Sec-Ch-Ua" "\"Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104\"")
("Dnt" "1")
("Sec-Ch-Ua-Mobile" "?0")
("User-Agent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36")
("Sec-Ch-Ua-Platform" "\"Linux\"")
("Accept" "*/*")
("Sec-Fetch-Site" "same-origin")
("Sec-Fetch-Mode" "cors")
("Sec-Fetch-Dest" "empty")
("Referer" "http://localhost:35901/")
("Accept-Encoding" "gzip, deflate, br")
("Accept-Language" "en-US,en;q=0.9,zh-TW;q=0.8,zh;q=0.7,zh-CN;q=0.6")
("Content" "")))
(error 500
(wrong-type-argument number-or-marker-p nil))
I've tried this setup too and encountered the same issue: The node info cannot be shown (resulting in that documented error 500), though the nodes themselves are displayed in the graph correctly. The org-roam manual says org-roam-directory needs to be absolute paths.
Same issue here, did anybody figure out a fix?
Unfortunately no, I just consolidated my org files under a single repo that I wanted org-roam functionality. My emacs-fu is just not good enough to properly solve the issue.
Same problem here, is there anyone who found a fix?
Same issue here, I have this in my .dir-locals.el
((nil . ((eval . (progn
(setq-local org-roam-directory (file-name-directory (file-truename ".dir-locals.el")))
(setq-local org-roam-db-location (concat org-roam-directory "org-roam.db")))))))
Same issue here.
If set org-roam-directory in init.el then restart Emacs, the org-roam-ui is back in normal status with the correct node's text.
An interesting approach to project based org-mode todo/agenda management is taken by Sylvain Rousseau
emacs package.
I also use this setting:
(setq org-agenda-files "~/.emacs-agenda.txt")
where this file (not a list!), contains the list of my (project based) org-mode todo agenda files
~/work/bu/org-info/todo.org
~/work/bv/box-up/todo.org
Same issue here.
If set
org-roam-directoryin init.el then restart Emacs, the org-roam-ui is back in normal status with the correct node's text.
UPDATE:
I think I figured out this issue from my use case.
Background:
I set the org-roam-directory in my .dir-locals.el with configuration below,
...
(eval . (setq-local org-roam-directory <my-project-path>))
...
And once I would like to check and see this graphical org-roam-ui, I M-x org-roam-ui-mode then org-roam-ui-open from that buffer, this will create process for org-roam-ui if I M-x list-processes.
I have multiple Org-roam databases and the org-roam-directory changes every time I switch the buffer, and in case that I want to see the graphicals, I do the same thing as above (M-x org-roam-ui-mode then M-x org-roam-ui-open)...Things come to chaos if I didn't disable the graphicals by M-x org-roam-ui-mode again from previous buffer...In this case, I can see many processes of 'httpd' and 'websocket' there in list-processes.
Fix:
I kill all the processes of 'httpd' and 'websocket', and do M-x org-roam-ui-mode then M-x org-roam-ui-open from scratch, the org-roam-ui is back in normal status with the correct node's text.
Before I switch to another buffer, in order to initiate the new org-roam-directory value from .dir-locals.el, I should execute M-x org-roam-ui-mode to disable. After that, do the same procedure for new graphical org-roam-ui view, it is fine now.
I simply call this function manually as a workaround, then reload the web page in my browser:
(defun my/org-roam-swap-work-and-home ()
"Swap between home and work org roam databases."
(interactive)
(if (equal org-roam-directory "~/work/org/roam/home/")
(setq org-roam-directory "~/work/org/roam/work/"
org-roam-db-location "~/.cache/emacs/org-roam-work.db")
(setq org-roam-directory "~/work/org/roam/home/"
org-roam-db-location "~/.cache/emacs/org-roam.db"))
(org-roam-db-sync))
Hello, me too I have this problem. Is this stale or did somebody find a fix?
I think I found a fix. As far as my understanding goes, the httpd server is running in some other directory, so that it doesn't hold the org-roam-directory variable from .dir-locals.el when it serves a request.
On startup of org-roam-ui-mode though, the org-roam-directory variable is set accorrdingly.
Therefore my idea was to save the value of org-roam-directory at startup of org-roam-ui-mode and reset org-roam-directory to this saved value.
Define new variable
;;; org-roam-ui.el --- User Interface for Org-roam -*- coding: utf-8; lexical-binding: t; -*-
(defvar org-roam-ui--roam-directory nil
"Var to keep track of the current org-roam-directory, used in servlet")
Save value of org-roam-directory inside org-roam-ui--roam-directory
(define-minor-mode
org-roam-ui-mode
...
(cond
(org-roam-ui-mode
;;; check if the default keywords actually exist on `orb-preformat-keywords'
;;; else add them
(setq-local httpd-port org-roam-ui-port)
(setq httpd-root org-roam-ui-app-build-dir)
(setq org-roam-ui--roam-directory org-roam-directory)
(httpd-start)
...
Set value of org-roam-directory when serving
(defservlet* node/:id text/plain ()
"Servlet for accessing node content."
(setq org-roam-directory org-roam-ui--roam-directory)
(insert (org-roam-ui--get-text (org-link-decode id)))
(httpd-send-header t "text/plain" 200 :Access-Control-Allow-Origin "*"))