From dee540b62f98f8da3bbe887039b32e38e3b8f82f Mon Sep 17 00:00:00 2001 From: Leo Vivier Date: Sat, 9 May 2020 13:47:56 +0200 Subject: [PATCH] (fix): do not store empty-string refs in db (#586) * (fix): do not store empty-string refs in db * Error when ROAM_KEY is empty * Handle nil Co-authored-by: Jethro Kuan --- org-roam.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/org-roam.el b/org-roam.el index 1478416..62d8356 100644 --- a/org-roam.el +++ b/org-roam.el @@ -382,13 +382,17 @@ current buffer is used." (defun org-roam--extract-ref () "Extract the ref from current buffer and return the type and the key of the ref." - (if-let ((ref (cdr (assoc "ROAM_KEY" (org-roam--extract-global-props '("ROAM_KEY")))))) - (let* ((type (org-roam--ref-type ref)) - (key (cond ((string= "cite" type) - (s-chop-prefix (org-roam--cite-prefix ref) ref)) - (t ref)))) - (cons type key)) - nil)) + (pcase (cdr (assoc "ROAM_KEY" + (org-roam--extract-global-props '("ROAM_KEY")))) + ('nil nil) + ((pred string-empty-p) + (user-error "ROAM_KEY cannot be empty")) + (ref + (let* ((type (org-roam--ref-type ref)) + (key (cond ((string= "cite" type) + (s-chop-prefix (org-roam--cite-prefix ref) ref)) + (t ref)))) + (cons type key))))) (defun org-roam--ref-type (ref) "Determine the type of the REF from the prefix."