Skip to content

Commit

Permalink
Raise an error if trying to set obsidian-directory to a directory tha…
Browse files Browse the repository at this point in the history
…t doesn't exist
  • Loading branch information
jayemar committed Dec 4, 2024
1 parent 3199daf commit d9562b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions obsidian.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@
:initialize #'custom-initialize-reset
:set (lambda (symbol value)
(let ((full-path (expand-file-name value)))
(message "Setting %s to %s" symbol full-path)
(set-default symbol full-path))))
(if (file-exists-p full-path)
(progn
(message "Setting %s to %s" symbol full-path)
(set-default symbol full-path))
(user-error (format "Directory %s doesn't exist" full-path))))))

(defcustom obsidian-inbox-directory nil
"Subdir to create notes using `obsidian-capture'."
Expand Down Expand Up @@ -178,7 +181,7 @@ You most likely want to run `obsidian-change-vault'."
(progn
(customize-set-value 'obsidian-directory final-path)
(message "Obsidian vault set to: %s" obsidian-directory))
(user-error (format "File %s doesn't exist" final-path)))))
(user-error (format "Directory %s doesn't exist" final-path)))))

;;;###autoload
(defun obsidian-change-vault (&optional path)
Expand Down
2 changes: 2 additions & 0 deletions tests/test-obsidian.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
;; Change vault to a non-existent directory
(expect (obsidian-change-vault "/path/that/does/not/exist")
:to-throw 'user-error)
(expect (setopt obsidian-directory "/path/that/does/not/exist")
:to-throw 'user-error)
;; Change vault path to test-dir and verify change
(obsidian-change-vault obsidian--test-dir)
(expect obsidian-directory :to-equal obsidian--test-dir)
Expand Down

0 comments on commit d9562b6

Please sign in to comment.