mdelobelle / metadatamenu

For data management enthusiasts : type and manage the metadata of your notes.
https://mdelobelle.github.io/metadatamenu
MIT License
478 stars 27 forks source link

Bug when creating files in Templater's template folder #604

Closed holroy closed 4 months ago

holroy commented 4 months ago

While testing out a new folder template within Templater I triggered the following error message in metadata-menu v. 0.8.3:

plugin:metadata-menu:24333 Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'fieldLookup' in undefined
    at eval (plugin:metadata-menu:24333:95)
    at Array.filter (<anonymous>)
    at eval (plugin:metadata-menu:24333:37)
    at Array.forEach (<anonymous>)
    at FieldIndex.getFilesLookupAndFormulaFieldsExists (plugin:metadata-menu:24329:37)
    at FieldIndex.indexFields (plugin:metadata-menu:23939:10)
    at async eval (plugin:metadata-menu:23870:11)

I've tracked it down to the following line in your source:

https://github.com/mdelobelle/metadatamenu/blob/9d8c694d020441708643be1b15bd289f526af90b/src/index/FieldIndex.ts#L594-L595

Before doing ... in something you should check that the something exists, so please change this to something like

 const dvLookupFields = fields.filter(f => f.isRoot() && f.type === "Lookup" && 
    this.dv.api.page(filePath) &&
    f.name in this.dv.api.page(filePath)) 

And I'm not sure if other measures needs to be taken as well. But at least this change needs to be done to avoid metadata-menu to interfere in otherwise unrelated business.


A little more explanation on what caused this, was that my settings for Templater was to create a file in the same folder, which just happened to be the templates folder, and this triggered this bug. Further testing showed that simply doing a create new note in this folder triggers this bug.

mdelobelle commented 4 months ago

good catch. will be fixed in the next version

mdelobelle commented 4 months ago

fixed in 0.8.4