jplattel / obsidian-query-language

An Obsidian plugin allowing you to query your notes
176 stars 6 forks source link

TypeErrors using simple query #15

Open HEmile opened 3 years ago

HEmile commented 3 years ago

Hi, I'm getting a TypeError on every edit of a file, and the index won't build. It's a small test vault, and I don't have any plugins installed.

The error:

VM105424:1915 TypeError: Cannot read property 'remove' of undefined
    at FuseSearchIndex.removeFile (eval at evalFunc (app.js:1), <anonymous>:1910:37)
    at ObsidianQueryLanguagePlugin.eval (eval at evalFunc (app.js:1), <anonymous>:27226:37)
    at step (eval at evalFunc (app.js:1), <anonymous>:79:23)
    at Object.eval [as next] (eval at evalFunc (app.js:1), <anonymous>:60:53)
    at fulfilled (eval at evalFunc (app.js:1), <anonymous>:50:58)

VM105424:1919 Uncaught (in promise) TypeError: Cannot read property 'add' of undefined
    at FuseSearchIndex.addFile (eval at evalFunc (app.js:1), <anonymous>:1919:33)
    at ObsidianQueryLanguagePlugin.eval (eval at evalFunc (app.js:1), <anonymous>:27227:37)
    at step (eval at evalFunc (app.js:1), <anonymous>:79:23)
    at Object.eval [as next] (eval at evalFunc (app.js:1), <anonymous>:60:53)
    at fulfilled (eval at evalFunc (app.js:1), <anonymous>:50:58
jplattel commented 3 years ago

Does this problem persist if you restart/reload the entire vault?

HEmile commented 3 years ago

Yes, I've force-reload the vault several times

fernandes commented 3 years ago

hi @jplattel I'm facing the same error, doing some troubleshooting I could realize two things

  1. this problem happens because the Fuse Index is null, so this is only a side effect when a problem happened during the build of the index
  2. In my case, the problem with building the index, was happening here

I figure out that I had a note with tags: [] on the front matter, that was causing the trouble

A possible would fix would be (but I have no idea if it makes sense hahaha)

if (metadata?.tags && tags !== null) {
  tags = tags.concat(metadata.tags.map(tag => tag.tag))
}

In my case changing the front matter, worked 💯

jplattel commented 3 years ago

Hey @fernandes... Woah, thanks for the deepdive! I'm able to replicate this now indeed! I'll have a look at the fix you suggested for the next release!

fernandes commented 3 years ago

awesome! glad I could help! thanks for the amazing work! 🙇