obsidian-query-language icon indicating copy to clipboard operation
obsidian-query-language copied to clipboard

TypeErrors using simple query

Open HEmile opened this issue 3 years ago • 5 comments

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

HEmile avatar Mar 11 '21 16:03 HEmile

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

jplattel avatar Mar 11 '21 16:03 jplattel

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

HEmile avatar Mar 11 '21 17:03 HEmile

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 💯

fernandes avatar Jun 01 '21 15:06 fernandes

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!

jplattel avatar Jun 03 '21 13:06 jplattel

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

fernandes avatar Jun 03 '21 13:06 fernandes