diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 07:21:44 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 07:21:44 -0500 |
| commit | 12fb0108ba217f06fb9d40da8431d49540650402 (patch) | |
| tree | 4d2c6630b3a6bc8f13de45697bc88ba89a257389 /modules/org-agenda-config.el | |
| parent | bc9652752c231e8634a90c875ed6d206ff172458 (diff) | |
| download | dotemacs-12fb0108ba217f06fb9d40da8431d49540650402.tar.gz dotemacs-12fb0108ba217f06fb9d40da8431d49540650402.zip | |
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.
Diffstat (limited to 'modules/org-agenda-config.el')
| -rw-r--r-- | modules/org-agenda-config.el | 22 |
1 files changed, 15 insertions, 7 deletions
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. |
