Org-roam files expected structure / no node at point error

Easy to reproduce error:

In an org-roam file, if I move the #+title: cool title line from after the property drawer containing the UUID to before that property drawer, and then evaluate org-roam-tag-add, I get a “no node at point” error.

Another case scenario:

I want to add filetags through a script that does not use org-roam-tag-add. I don’t recon that either Org Syntax or Org Element API point to a specific structure or guidelines on where to place #+filetags: cool_tag: so I add it at the beginning of the file because no documentation (that I’ve found), tells me otherwise.

Then when I manually evaluate org-roam-tag-add I get a “no node at point” error.

Properties can be inserted at the buffer level. 
That means they apply before the first headline and can be inherited by all entries in a file.
Property blocks defined before the first headline must be at the top of the buffer with only comments above them. 

I found the following in the org-mode manual :Property Syntax (The Org Manual)

There is a very specific syntax to where property drawers can be defined - both at the buffer level and at the headline level. Unless that syntax is followed things would go awry. :slightly_frowning_face:

Suggestion:

You can use #'org-roam-end-of-metadata to programatically accomplish what you want to do, that is put cursor where the “metadata” ends. I think it would be much easier to accomplish this in elisp than for say in Bash script.

Thanks, it is exactly what I was looking for.

Property blocks defined before the first headline must be at the top of the buffer with only comments above them.

Also, as someone just pointed out to me, there is Org Syntax, which gives the same answer:

All elements before the first heading in a document lie in a special section called the zeroth section. It may be preceded by blank lines. Unlike a normal section, the zeroth section can immediately contain a property drawer, optionally preceded by comments.