From 1981dc361741d0a1f57b5cbf67ec0feb22a9796d Mon Sep 17 00:00:00 2001 From: Samuel Culpepper Date: Thu, 23 Feb 2023 07:43:47 +0100 Subject: [PATCH] utils: descendant-of-p: Defend against nils (#2319) 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)) ... --- org-roam-utils.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org-roam-utils.el b/org-roam-utils.el index 275a2a7..3c7e433 100644 --- a/org-roam-utils.el +++ b/org-roam-utils.el @@ -120,7 +120,7 @@ SPEC is a list, as per `dolist'." ;;; File utilities (defun org-roam-descendant-of-p (a b) "Return t if A is descendant of B." - (unless (equal (file-truename a) (file-truename b)) + (unless (and a b (equal (file-truename a) (file-truename b))) (string-prefix-p (replace-regexp-in-string "^\\([A-Za-z]\\):" 'downcase (expand-file-name b) t t) (replace-regexp-in-string "^\\([A-Za-z]\\):" 'downcase (expand-file-name a) t t))))