From 523cad135153dfaa68da8a1845d0a8e02eb4b67c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 24 May 2026 07:21:44 -0500 Subject: fix(org): surface directory-scan failures instead of crashing or hiding them The refile target scan caught permission-denied and silently dropped the directory, and would crash outright on a missing root (only permission-denied was caught, so a missing code-dir/projects-dir raised file-missing and aborted the whole build). The agenda build had the same crash: cj/add-files-to-org-agenda-files-list called directory-files on projects-dir with no existence check. Extracted cj/--org-refile-scan-dir, which warns (display-warning) and returns nil for a missing, unreadable, or permission-denied root so the rest of the scan continues. Guarded the agenda scan the same way. Both now log a concise warning naming the skipped directory rather than failing silently or fatally. Also fixed a latent bug surfaced here: org-refile-targets was never declared special, so under make compile cj/org-refile-in-file let-bound it lexically and the scoped targets never reached org-refile. Added (defvar org-refile-targets) so the binding stays dynamic when byte-compiled. Tests cover the helper (missing/permission-denied/normal) and the agenda missing-dir guard. --- modules/org-agenda-config.el | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'modules/org-agenda-config.el') diff --git a/modules/org-agenda-config.el b/modules/org-agenda-config.el index 22bc569c..231eff8a 100644 --- a/modules/org-agenda-config.el +++ b/modules/org-agenda-config.el @@ -149,13 +149,21 @@ the file keeps precedence." "Add todo.org files from immediate subdirectories of DIRECTORY. Only checks DIRECTORY/*/todo.org — does not recurse deeper." (interactive "D") - (let ((todo-files - (seq-filter - #'file-exists-p - (mapcar (lambda (dir) (expand-file-name "todo.org" dir)) - (seq-filter #'file-directory-p - (directory-files directory t "^[^.]")))))) - (setq org-agenda-files (append todo-files org-agenda-files)))) + (if (not (and (file-directory-p directory) (file-readable-p directory))) + ;; Non-fatal: a missing or unreadable project root shouldn't crash the + ;; whole agenda build — surface it and carry on with the other files. + (display-warning + 'org-agenda + (format "Agenda scan: project directory missing or unreadable, skipped: %s" + directory) + :warning) + (let ((todo-files + (seq-filter + #'file-exists-p + (mapcar (lambda (dir) (expand-file-name "todo.org" dir)) + (seq-filter #'file-directory-p + (directory-files directory t "^[^.]")))))) + (setq org-agenda-files (append todo-files org-agenda-files))))) ;; ---------------------------- Rebuild Org Agenda --------------------------- ;; builds the org agenda list from all agenda targets with caching. -- cgit v1.2.3