Error message says "orb-edit-notes caught an error during capture". How to solve?

I am tring to set up org-roab-bibtex in doom emacs but keep getting the following error when I try to open new note files in ivy-bibtex:

orb-edit-notes caught an error during capture: cite:kosciulek2001 is not a valid ref

Have no idea how to solve it . Grateful for support. This is what the relevant part of my config.el file looks like:

;;------------------------------------------------------------------------------------
;;  org
;;------------------------------------------------------------------------------------
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
;; (setq org-directory "~/org/zettelkasten")

;;------------------------------------------------------------------------------------
;;  pdf-tools
;;------------------------------------------------------------------------------------
(use-package! pdf-tools
  :load-path "site-lisp/pdf-tools/lisp"
  :magic ("%PDF" . pdf-view-mode)
  :config
  (pdf-tools-install :no-query)
  (setq-default pdf-view-display-size 'fit-page)
  (setq pdf-annot-activate-created-annotations t)
  (setq pdf-view-resize-factor 1.1)
  (setq pdf-view-use-unicode-ligther nil))

;;-------------------------------------------------------------------------------------
;;  deft
;;-------------------------------------------------------------------------------------
(setq deft-directory "/Users/joafr/org/zettelkasten/"
      deft-use-filename-as-title nil)

;;-------------------------------------------------------------------------------------
;;  ivy-bibtex
;;-------------------------------------------------------------------------------------
(autoload 'ivy-bibtex "ivy-bibtex" "" t)
;; ivy-bibtex requires ivy's `ivy--regex-ignore-order` regex builder, which
;; ignores the order of regexp tokens when searching for matching candidates.
;; Add something like this to your init file:
(setq ivy-re-builders-alist
      '((ivy-bibtex . ivy--regex-ignore-order)
        (t . ivy--regex-plus)))
(setq bibtex-completion-bibliography "/Users/joafr/Documents/bibfiles/library.bib"
      bibtex-completion-library-path "/Users/joafr/Documents/bibpdfs"
      bibtex-completion-notes-path "/Users/joafr/org/zettelkasten/"
      bibtex-completion-notes-template-multiple-files "")


;;;;;;;;;;UGLY CODE, SHOULD BE PLACED ELSEWHERE BUT DO NOT DARE TO EDIT NOW;;;;;;;;;;
(setq org-directory "/Users/joafr/org/zettelkasten/"
      org-roam-directory "/Users/joafr/org/zettelkasten/")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;------------------------------------------------------------------------------------
;;  org-ref
;;------------------------------------------------------------------------------------
(use-package org-ref
    :after org
    :commands
    (org-ref-cite-hydra/body
     org-ref-bibtex-hydra/body)
    :init
    (let ((cache-dir (concat doom-cache-dir "org-ref")))
    (unless (file-exists-p cache-dir)
      (make-directory cache-dir t))
    (setq orhc-bibtex-cache-file (concat cache-dir "/orhc-bibtex-cache")))
    :config
    (setq
         org-ref-completion-library 'org-ref-ivy-cite
         org-ref-get-pdf-filename-function 'org-ref-get-pdf-filename-helm-bibtex
         org-ref-default-bibliography (list "/Users/joafr/Documents/bibfiles/library.bib")
         org-ref-bibliography-notes "/Users/joafr/org/zettelkasten/"
         org-ref-note-title-format "* TODO %y - %t\n :PROPERTIES:\n  :Custom_ID: %k\n  :NOTER_DOCUMENT: %F\n :ROAM_KEY: cite:%k\n  :AUTHOR: %9a\n  :JOURNAL: %j\n  :YEAR: %y\n  :VOLUME: %v\n  :PAGES: %p\n  :DOI: %D\n  :URL: %U\n :END:\n\n"
         org-ref-notes-directory "/Users/joafr/org/zettelkasten/"
         org-ref-notes-function 'orb-edit-notes
    ))

;;--------------------------------------------------------------------------------------
;;  org-roam
;;--------------------------------------------------------------------------------------
(use-package org-roam
  :hook (org-load . org-roam-mode)
  :commands (org-roam-buffer-toggle-display
             org-roam-find-file
             org-roam-graph
             org-roam-insert
             org-roam-switch-to-buffer
             org-roam-dailies-date
             org-roam-dailies-today
             org-roam-dailies-tomorrow
             org-roam-dailies-yesterday)
  :preface
  ;; Set this to nil so we can later detect whether the user has set a custom
  ;; directory for it, and default to `org-directory' if they haven't.
  (defvar org-roam-directory nil)
  :init
  :config
  (setq org-roam-directory (expand-file-name (or org-roam-directory "roam")
                                             org-directory)
        org-roam-verbose nil  ; https://youtu.be/fn4jIlFwuLU
        org-roam-buffer-no-delete-other-windows t ; make org-roam buffer sticky
        org-roam-completion-system 'default
)

  ;; Normally, the org-roam buffer doesn't open until you explicitly call
  ;; `org-roam'. If `+org-roam-open-buffer-on-find-file' is non-nil, the
  ;; org-roam buffer will be opened for you when you use `org-roam-find-file'
  ;; (but not `find-file', to limit the scope of this behavior).
  (add-hook 'find-file-hook
    (defun +org-roam-open-buffer-maybe-h ()
      (and +org-roam-open-buffer-on-find-file
           (memq 'org-roam-buffer--update-maybe post-command-hook)
           (not (window-parameter nil 'window-side)) ; don't proc for popups
           (not (eq 'visible (org-roam-buffer--visibility)))
           (with-current-buffer (window-buffer)
             (org-roam-buffer--get-create)))))

  ;; Hide the mode line in the org-roam buffer, since it serves no purpose. This
  ;; makes it easier to distinguish among other org buffers.
  (add-hook 'org-roam-buffer-prepare-hook #'hide-mode-line-mode))


;; Since the org module lazy loads org-protocol (waits until an org URL is
;; detected), we can safely chain `org-roam-protocol' to it.
(use-package org-roam-protocol
  :after org-protocol)


(use-package company-org-roam
  :after org-roam
  :config
  (set-company-backend! 'org-mode '(company-org-roam company-yasnippet company-dabbrev)))

(use-package! org-roam-bibtex
  :after org-roam
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :config
  (require 'org-ref))

(setq org-roam-bibtex-preformat-keywords
      '("citekey" "title" "url" "file" "author-or-editor" "keywords"))
(setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)
           ""
           :file-name "${citekey}"
           :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}

- tags ::
- keywords ::

\n* ${citekey}: ${title}\n  :PROPERTIES:\n  :Custom_ID: ${citekey}\n  :URL: \n  :AUTHOR: ${author}\n  :NOTER_DOCUMENT: ${file}\n  :NOTER_PAGE: \n  :END:\n\n"

           :unnarrowed t)))

;;----------------------------------------------------------------------------------------
;;  org-noter
;;-----------------------------------------------------------------------------------------
(use-package org-noter
  :after org
  :config
  (setq
   ;; The WM can handle splits - var tidigare "other-frame"
   org-noter-notes-window-location 'horizontal-split
   ;; Please stop opening frames
   org-noter-always-create-frame nil
   ;; I want to see the whole file
   org-noter-hide-other nil
   ;; Everything is relative to the main notes file
   org-noter-notes-search-path (list "/Users/joafr/org/zettelkasten/")
)
   )

;;-----------------------------------------------------------------------------------------
;;  org-capture
;;------------------------------------------------------------------------------------------
;; Actually start using templates
(after! org-capture
  ;; Firefox and Chrome
  (add-to-list 'org-capture-templates
               '("P" "Protocol" entry ; key, name, type
                 (file+headline +org-capture-notes-file "Inbox") ; target
                 "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?"
                 :prepend t ; properties
                 :kill-buffer t))
  (add-to-list 'org-capture-templates
               '("L" "Protocol Link" entry
                 (file+headline +org-capture-notes-file "Inbox")
                 "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n"
                 :prepend t
                 :kill-buffer t))
)

@joafr Hi, it looks like you are using Doom Emacs. Do you have the +roam flag in your init.el file? If yes, then (use-package org-roam ...) in your config.el is superfluous and actually harmful potentially leading to loading issues that are probably causing your issue.

Also, what are you trying to achieve with (autoload 'ivy-bibtex ...)? You should probably use the biblio module in your init.el or (use-package! ivy-bibtex ...) (but again not both).

Note that the package company-org-roam has long been deprecated. I don’t know whether using this outdated package may impact Org roam loading, but you probably don’t need it.

The configuration for org-roam-bibtex looks fine except that you can put the (setq org-roam-bibtex-preformat-keywords ...) and (setq orb-templates ...) statements inside (use-package! org-roam-bibtex ...), not outside. But that’s a not big deal.

1 Like

Yes, I am on Doom Emacs and your suggestions wiped out the error! Thanks a lot! My code now looks like this (and I think I just learned how and why to use after! instead of use-package!):

(after! org
  :config
  (setq org-directory "/Users/joafr/org/zettelkasten/"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;------------------------------------------------------------------------------------
;;  org-ref
;;------------------------------------------------------------------------------------
(use-package! org-ref
    :after org
    :commands
    (org-ref-cite-hydra/body
     org-ref-bibtex-hydra/body)
    :init
    (let ((cache-dir (concat doom-cache-dir "org-ref")))
    (unless (file-exists-p cache-dir)
      (make-directory cache-dir t))
    (setq orhc-bibtex-cache-file (concat cache-dir "/orhc-bibtex-cache")))
    :config
    (setq
         org-ref-completion-library 'org-ref-ivy-cite
         org-ref-get-pdf-filename-function 'org-ref-get-pdf-filename-helm-bibtex
         org-ref-default-bibliography (list "/Users/joafr/Documents/bibfiles/library.bib")
         org-ref-bibliography-notes "/Users/joafr/org/zettelkasten/"
         org-ref-note-title-format "* TODO %y - %t\n :PROPERTIES:\n  :Custom_ID: %k\n  :NOTER_DOCUMENT: %F\n :ROAM_KEY: cite:%k\n  :AUTHOR: %9a\n  :JOURNAL: %j\n  :YEAR: %y\n  :VOLUME: %v\n  :PAGES: %p\n  :DOI: %D\n  :URL: %U\n :END:\n\n"
         org-ref-notes-directory "/Users/joafr/org/zettelkasten/"
         org-ref-notes-function 'orb-edit-notes
    ))

;;--------------------------------------------------------------------------------------
;;  org-roam
;;--------------------------------------------------------------------------------------
;;(after! org-roam
;;  :hook (org-load . org-roam-mode)
;;  :commands (org-roam-buffer-toggle-display
;;             org-roam-find-file
;;             org-roam-graph
;;             org-roam-insert
;;             org-roam-switch-to-buffer
;;             org-roam-dailies-date
;;             org-roam-dailies-today
;;             org-roam-dailies-tomorrow
;;             org-roam-dailies-yesterday)
;;  :preface
  ;; Set this to nil so we can later detect whether the user has set a custom
  ;; directory for it, and default to `org-directory' if they haven't.
;;  (defvar org-roam-directory nil)
;;  :init
;;  :config
;;  (setq org-roam-directory (expand-file-name (or org-roam-directory "roam")
;;                                             org-directory)
;;        org-roam-verbose nil  ; https://youtu.be/fn4jIlFwuLU
;;        org-roam-buffer-no-delete-other-windows t ; make org-roam buffer sticky
;;        org-roam-completion-system 'default
;;)

  ;; Normally, the org-roam buffer doesn't open until you explicitly call
  ;; `org-roam'. If `+org-roam-open-buffer-on-find-file' is non-nil, the
  ;; org-roam buffer will be opened for you when you use `org-roam-find-file'
  ;; (but not `find-file', to limit the scope of this behavior).
;;  (add-hook 'find-file-hook
;;    (defun +org-roam-open-buffer-maybe-h ()
;;      (and +org-roam-open-buffer-on-find-file
;;           (memq 'org-roam-buffer--update-maybe post-command-hook)
;;           (not (window-parameter nil 'window-side)) ; don't proc for popups
;;           (not (eq 'visible (org-roam-buffer--visibility)))
;;           (with-current-buffer (window-buffer)
;;             (org-roam-buffer--get-create)))))

  ;; Hide the mode line in the org-roam buffer, since it serves no purpose. This
  ;; makes it easier to distinguish among other org buffers.
;;  (add-hook 'org-roam-buffer-prepare-hook #'hide-mode-line-mode))


;; Since the org module lazy loads org-protocol (waits until an org URL is
;; detected), we can safely chain `org-roam-protocol' to it.
;; (use-package org-roam-protocol
;;  :after org-protocol)

;;(use-package company-org-roam
;;  :after org-roam
;;  :config
;;  (set-company-backend! 'org-mode '(company-org-roam company-yasnippet company-dabbrev)))
;;(use-package! org-roam
;;  :config
(after! org-roam
  :config
  (setq org-roam-directory "/Users/joafr/org/zettelkasten/"))

(use-package! org-roam-bibtex
  :after org-roam
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :config
  (require 'org-ref)
  (setq org-roam-bibtex-preformat-keywords
      '("citekey" "title" "url" "file" "author-or-editor" "keywords"))
  (setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)
           ""
           :file-name "${citekey}"
           :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}

- tags ::
- keywords ::

\n* ${citekey}: ${title}\n  :PROPERTIES:\n  :Custom_ID: ${citekey}\n  :URL: \n  :AUTHOR: ${author}\n  :NOTER_DOCUMENT: ${file}\n  :NOTER_PAGE: \n  :END:\n\n"

           :unnarrowed t))))

;;----------------------------------------------------------------------------------------
;;  org-noter
;;-----------------------------------------------------------------------------------------
(use-package! org-noter
  :after org
  :config
  (setq
   ;; The WM can handle splits - var tidigare "other-frame"
   org-noter-notes-window-location 'horizontal-split
   ;; Please stop opening frames
   org-noter-always-create-frame nil
   ;; I want to see the whole file
   org-noter-hide-other nil
   ;; Everything is relative to the main notes file
   org-noter-notes-search-path (list "/Users/joafr/org/zettelkasten/")
)
   )

;;-----------------------------------------------------------------------------------------
;;  org-capture
;;------------------------------------------------------------------------------------------
;; Actually start using templates
(after! org-capture
  ;; Firefox and Chrome
  (add-to-list 'org-capture-templates
               '("P" "Protocol" entry ; key, name, type
                 (file+headline +org-capture-notes-file "Inbox") ; target
                 "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?"
                 :prepend t ; properties
                 :kill-buffer t))
  (add-to-list 'org-capture-templates
               '("L" "Protocol Link" entry
                 (file+headline +org-capture-notes-file "Inbox")
                 "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n"
                 :prepend t
                 :kill-buffer t))
)

Yeah, I’ve been using Emacs for about ten years before trying Doom. I gave up on my first attempt to use it and the second attempt made me frustrated for a month before I learned my way through it. Now it’s working like a charm.

Generally yes. In the particular case of org-roam-directory, it’s better to set it outside the after! block. Somewhere near the top of your config.el. The +roam module initializes org-roam-directory and then also sets it during package configuration unless it’s already set by user. It should not cause problems in the after! block though, but one never knows what else can interfere.

1 Like