Skip to content

utils: descendant-of-p: Defend against nils#2319

Merged
jethrokuan merged 1 commit intoorg-roam:mainfrom
qzdl:master
Feb 23, 2023
Merged

utils: descendant-of-p: Defend against nils#2319
jethrokuan merged 1 commit intoorg-roam:mainfrom
qzdl:master

Conversation

@qzdl
Copy link
Copy Markdown
Contributor

@qzdl qzdl commented Feb 22, 2023

This has an effect on find-file-hook for totally unrelated files, through the callchain of `org-roam-db-autosync--setup-file-h -> org-roam-file-p -> org-roam-descendant-of-p'.

From an org file, inside a project-el project, (find-file "some/other/file") will intermittently reproduce this error:

org-roam-descendant-of-p: Wrong type argument: arrayp, nil

If this fix seems inappropriate -- it could amount to surppressing a valid error in routine calls -- then I would advise throwing an explicit signal here, or finding a safer way to get the path inside `org-roam-file-p'; the current means:

(or file (buffer-file-name (buffer-base-buffer)))

.. can result in nil, which then bleeds errors into use elsewhere.

for posterity, here is the full calling context I'm referring to, from `org-roam-file-p'.

(let* ((path (or file (buffer-file-name (buffer-base-buffer))))
(ext (when path (org-roam--file-name-extension path)))
(ext (if (string= ext "gpg")
(org-roam--file-name-extension (file-name-sans-extension path))
ext))
(org-roam-dir-p (org-roam-descendant-of-p path
org-roam-directory))
...

Motivation for this change

I should be able to find-file to any file, outside of org-roam, without error bleed from this package's hook functions.

This has an effect on find-file-hook for totally unrelated files,
through the callchain of `org-roam-db-autosync--setup-file-h ->
org-roam-file-p -> org-roam-descendant-of-p'.

From an org file, inside a project-el project, (find-file
"some/other/file") will intermittently reproduce this error:

   org-roam-descendant-of-p: Wrong type argument: arrayp, nil

If this fix seems inappropriate -- it could amount to surppressing a
valid error in routine calls -- then I would advise throwing an
explicit signal here, or finding a safer way to get the `path` inside
`org-roam-file-p'; the current means:

    (or file (buffer-file-name (buffer-base-buffer)))

.. can result in nil, which then bleeds errors into use elsewhere.

for posterity, here is the full calling context I'm referring to, from
`org-roam-file-p'.

  (let* ((path (or file (buffer-file-name (buffer-base-buffer))))
         (ext (when path (org-roam--file-name-extension path)))
         (ext (if (string= ext "gpg")
                  (org-roam--file-name-extension (file-name-sans-extension path))
                ext))
         (org-roam-dir-p (org-roam-descendant-of-p path
         org-roam-directory))
         ...
@jethrokuan jethrokuan merged commit 1981dc3 into org-roam:main Feb 23, 2023
@jethrokuan
Copy link
Copy Markdown
Member

thanks! the lint error was on main so i fixed it.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants