Issues with org-roam-bibtex

Hi everyone! I’ve been using org-roam-bibex for a while but since yesterday every time I try to create a note (via edit note) it gives me (wrong-type-argument stringp nil) error.

Whole debug entry gives me this;

     (wrong-type-argument stringp nil)
     compare-strings(nil 0 nil "pdf" 0 nil t)
     member-ignore-case(nil ("pdf"))
      orb-process-file-field("bibtexkey")
      orb--preformat-template(("r" "ref" plain (function org-roam-capture--get-point) "" :file-name "bibtexkey" :head "#+TITLE: bibtexkey: ${title}\n#+ROAM_KEY: ${ref}\n" :unnarrowed t) (bibtex entry) ("number" . "2") ("=has-pdf=" . "⌘")))
      orb-edit-notes("bibtexkey")
      orb-edit-notes-ad(("bibtexkey"))
      apply(orb-edit-notes-ad ("bibtexkey"))
      bibtex-completion-edit-notes(("bibtexkey"))
      ivy-bibtex-edit-notes(("⌘ 2016-07-01 title article bibtexkey" ("=has-pdf=" . "⌘") ("date" . "2016-07-01") ("author" . "author") ("title" . "title") ("=type=" . "article") ("=key=" . "bibtexkey")))
      ivy-call()
      ivy-read("BibTeX entries: " (all entries) ...) :preselect nil :caller ivy-bibtex :history ivy-bibtex-history :action ivy-bibtex-open-any)
      ivy-bibtex(nil)
      funcall-interactively(ivy-bibtex nil)
      call-interactively(ivy-bibtex nil nil)
      command-execute(ivy-bibtex)

Does anybody know how to fix this?

Hi, I’ll need more information to debug this - the value of orb-templates and the BibTeX entry that causes the error.

Meanwhile, you can evaluate this:

(defun orb-process-file-field (citekey)
  "Process the 'file' BibTeX field and resolve if there are multiples.
Search the disk for the document associated with this BibTeX
entry.  The disk matching is based on looking in the
`bibtex-completion-library-path' for a file with the
CITEKEY.

If variable `orb-file-field-extensions' is non-nil, return only
the file paths with the respective extensions.

\(Mendeley, Zotero, normal paths) are all supported.  If there
are multiple files found the user is prompted to select which one
to enter."
  (when-let* ((entry (bibtex-completion-get-entry citekey))
              (paths (bibtex-completion-find-pdf entry)))
    (when-let ((extensions orb-file-field-extensions))
      (unless (listp extensions)
        (setq extensions (list extensions)))
      (setq paths (--filter
                   (member-ignore-case
                    (or (file-name-extension it) "") extensions)
                   paths)))
    (when paths
      (if (= (length paths) 1)
          (car paths)
        (completing-read "File to use: " paths)))))

and see if the issue disappears.

You are completely right. Issue was related to bibtex entry. I posted the full entry, do you know which part might caused this?

@article{herschthal2016SlavesSpaniards,
  title = {Slaves, {{Spaniards}}, and {{Subversion}} in {{Early Louisiana}}: {{The Persistent Fears}} of {{Black Revolt}} and {{Spanish Collusion}} in {{Territorial Louisiana}}, 1803\textendash 1812},
  shorttitle = {Slaves, {{Spaniards}}, and {{Subversion}} in {{Early Louisiana}}},
  author = {Herschthal, Eric},
  date = {2016-07-01},
  journaltitle = {Journal of the Early Republic},
  shortjournal = {Journal of the Early Republic},
  volume = {36},
  pages = {283--311},
  publisher = {{University of Pennsylvania Press}},
  issn = {02751275},
  url = {http://search.ebscohost.com/login.aspx?direct=true&db=edsjsr&AN=edsjsr.jearlyrepublic.36.2.283&site=eds-live},
  urldate = {2020-12-08},
  abstract = {Scholars of the early republic have tended to overlook the extent to which elite U.S. officials feared that enslaved and free people of color might collude with local Spanish officials in the Louisiana borderlands, and in so doing threaten plans for westward expansion. By exposing these fears and explaining the reasons for them, this article attempts to show how enslaved and free people of color, combined with local Spanish officials, posed a serious challenge to the United States' attempt to gain control over the trans-Appalachian west. Several factors explain why U.S. officials feared Spanish and black collusion: First, U.S. officials worried that Louisiana's black population might rebel at the loss of the rights granted to them during period of Spanish colonial rule. Second, after the U.S. took control of Louisiana, slaves continually escaped to Spanish Texas with the explicit encouragement of local Spanish officials, who tried to weaken U.S. authority over Louisiana. Last, enslaved and free people of color exploited the tumult unleashed by the Spanish Atlantic empire's rapid collapse. By the end of the territorial period, U.S. officials' fears of a slave revolt, I argue, had less to do with the Haitian Revolution than with the Latin American Wars of Independence, which began in 1810. Ultimately, this paper suggests the need to take seriously the joint role played by local Spanish and black actors in the broader imperial struggle for the trans-Appalachian west.},
  file = {/Users/Eser/Library/Mobile Documents/com~apple~CloudDocs/readings/Herschthal Eric_2016_Slaves, Spaniards, and Subversion in Early Louisiana.pdf},
  keywords = {Aaron Burr Conspiracy,Black revolt,Borderlands,Coartación,Early republic,Free people of color,Haitian Revolution,James Madison,Nacodgoches,Napoleonic Wars,Natchitoches,Neutral Ground,Republic of West Florida,Slave conspiracy,Slave revolts,Spanish colonial Louisiana,Spanish empire,Spanish Wars of Independence,Territorial Louisiana,to_read,Trans-Appalachian west,U.S.-Spanish diplomacy,Westward expansion,William C.C. Claiborne},
  number = {2}
}

I’m not the OP, but I think I have a similar problem. Note creation just stopped working recently. I am using the melpa version. Evaluating the function you provided made no difference.

I used to open new notes with helm-bibtex. Now, pressing F9 on a reference without notes, does nothing (no error message either). Pressing F9 on a reference with notes already created does open the notes.

Also, for example evaluating, say, (orb-edit-notes “citekey-with-no-notes”) returns nil. But (orb-edit-notes “citekey-with-notes”) opens the notes file.

The value of orb-templates is:

((“r” “ref” plain #'org-roam-capture–get-point “” :file-name "{citekey}" :head "#+title: {title}, by {author-or-editor}\n#+roam_key: {ref}\n#+setupfile: options.org\n\n- tags ::\n- keywords :: {keywords}\n\n* Org noter notes\n :PROPERTIES:\n :Custom_ID: {citekey}\n :URL: {url}\n :AUTHOR: {author-or-editor}\n :NOTER_DOCUMENT: %(orb-process-file-field “{citekey}\")\n :NOTER_PAGE:\n :END:\n\n* {title}\n\n* dummy\n\n[[bibliographystyle:alpha]]\n[[bibliography:rvf.bib]]\n\n\n* COMMENT Local Variables\n\n# Local variables:\n# org-confirm-babel-evaluate: nil\n# eval: (org-babel-lob-ingest “options.org”)\n# eval: (org-sbe filter)\n# End:”))

I checked orb-roam-bibtex from git and I think that the last commit (c201728d) may be the culprit. Doing git checkout 807e13 solves this issue.

My issue is half-solved. It was mostly about the specific citation rather than org-ref-bibtex. For now, note creation on other citations work perfectly.

@noadlib So, is that specific citation working now? If not, if you give me more details about it, I’ll look into it. Also, do you use the patched function or the upstream one?

Also, for example evaluating, say, (orb-edit-notes “citekey-with-no-notes”) returns nil. But (orb-edit-notes “citekey-with-notes”) opens the notes file.

@rvf0068 That’s very strange, it’s working for me with the default value of orb-templates on the latest commit.

Sorry, the value of orb-templates you provided is unparsable to a human eye. Can’t help with that.

I didn’t need to. However, specific citation still gives the same error. I added the citation below.

@article{herschthal2016SlavesSpaniards,
  title = {Slaves, {{Spaniards}}, and {{Subversion}} in {{Early Louisiana}}: {{The Persistent Fears}} of {{Black Revolt}} and {{Spanish Collusion}} in {{Territorial Louisiana}}, 1803\textendash 1812},
  shorttitle = {Slaves, {{Spaniards}}, and {{Subversion}} in {{Early Louisiana}}},
  author = {Herschthal, Eric},
  date = {2016-07-01},
  journaltitle = {Journal of the Early Republic},
  shortjournal = {Journal of the Early Republic},
  volume = {36},
  pages = {283--311},
  publisher = {{University of Pennsylvania Press}},
  issn = {02751275},
  url = {http://search.ebscohost.com/login.aspx?direct=true&db=edsjsr&AN=edsjsr.jearlyrepublic.36.2.283&site=eds-live},
  urldate = {2020-12-08},
  abstract = {},
  file = {},
  keywords = {},
  number = {2}
}

@noadlib this is because you have an empty file field in your entry.

Check if this works for you (evaluate the function):

(defun orb-process-file-field (citekey)
  "Process the 'file' BibTeX field and resolve if there are multiples.
Search the disk for the document associated with this BibTeX
entry.  The disk matching is based on looking in the
`bibtex-completion-library-path' for a file with the
CITEKEY.

If variable `orb-file-field-extensions' is non-nil, return only
the file paths with the respective extensions.

\(Mendeley, Zotero, normal paths) are all supported.  If there
are multiple files found the user is prompted to select which one
to enter."
  (when-let* ((entry (bibtex-completion-get-entry citekey))
              (paths (bibtex-completion-find-pdf entry)))
    (when-let ((extensions orb-file-field-extensions))
      (unless (listp extensions)
        (setq extensions (list extensions)))
      (setq paths (--filter
                   (lambda ()
                     (when-let ((extension (file-name-extension it)))
                       (member-ignore-case extension extensions)))
                   paths)))
    (when paths
      (if (= (length paths) 1)
          (car paths)
        (completing-read "File to use: " paths)))))

I’ll merge it into master later

@mshevchuk Actually, original citation includes a file, I deleted it when I added in my comment because it had personal info.

@article{herschthal2016SlavesSpaniards,
  title = {Slaves, {{Spaniards}}, and {{Subversion}} in {{Early Louisiana}}: {{The Persistent Fears}} of {{Black Revolt}} and {{Spanish Collusion}} in {{Territorial Louisiana}}, 1803\textendash 1812},
  shorttitle = {Slaves, {{Spaniards}}, and {{Subversion}} in {{Early Louisiana}}},
  author = {Herschthal, Eric},
  date = {2016-07-01},
  journaltitle = {Journal of the Early Republic},
  shortjournal = {Journal of the Early Republic},
  volume = {36},
  pages = {283--311},
  publisher = {{University of Pennsylvania Press}},
  issn = {02751275},
  url = {http://search.ebscohost.com/login.aspx?direct=true&db=edsjsr&AN=edsjsr.jearlyrepublic.36.2.283&site=eds-live},
  urldate = {2020-12-08},
  abstract = {},
  file = {/Users/noadlib/Library/Mobile Documents/com~apple~CloudDocs/readings/Herschthal Eric_2016_Slaves, Spaniards, and Subversion in Early Louisiana.pdf},
  keywords = {},
  number = {2}
}

When I tried to evaluate the function it gave the error below.

Debugger entered--Lisp error: (void-variable orb-process-file-field)

Oh, that’s something with your installation. There is no orb-process-file-field variable in the function being evaluated. Such weird errors are an indication of stale compiled libraries. Try reinstalling org-roam-bibtex and who knows what else… Also, are you by chance using the native-comp Emacs branch?

Anyway, this modified version would only fix errors caused by empty “file” field, so it won’t help. But having a healthy Emacs installation that would allow to evaluate the above function is a must to move further.

It looks like your file is stored in iCloud. I have several

  1. Could it be possible that this cloud file is not synced to the local hard drive?
  2. The function bibtex-completion-find-pdf used by orb-process-file-field actually checks whether the file exists, relying on Emacs subroutines. Does Emacs have read access to your ~/Library folder?
  3. Is this the only bibtex entry with “file” pointing to iCloud throwing errors?

The following modification will allow to ignore any errors thrown while attempting to process the file field, which interrupt the note creation process:

(defun orb-process-file-field (citekey)
  "Process the 'file' BibTeX field and resolve if there are multiples.
Search the disk for the document associated with this BibTeX
entry.  The disk matching is based on looking in the
`bibtex-completion-library-path' for a file with the
CITEKEY.

If variable `orb-file-field-extensions' is non-nil, return only
the file paths with the respective extensions.

\(Mendeley, Zotero, normal paths) are all supported.  If there
are multiple files found the user is prompted to select which one
to enter."
  (condition-case nil
      (when-let* ((entry (bibtex-completion-get-entry citekey))
                  (paths (bibtex-completion-find-pdf entry)))
        (when-let ((extensions orb-file-field-extensions))
          (unless (listp extensions)
            (setq extensions (list extensions)))
          (setq paths (--filter
                       (lambda ()
                         (when-let ((extension (file-name-extension it)))
                           (member-ignore-case extension extensions)))
                       paths)))
        (when paths
          (if (= (length paths) 1)
              (car paths)
            (completing-read "File to use: " paths))))
    ;; ignore any errors that may be thrown by `bibtex-completion-find-pdf'
    ;; don't stop the capture process
    (error nil)))

If errors are thrown while trying to evaluate the function itself, try to fix your installation first.