TomNCatz / obsidian-gallery

Main Gallery to tag / filter / add notes to images. Display blocks to embed images inside notes. Display block to an image information
MIT License
41 stars 3 forks source link

Build Tag Cache error #25

Closed rubenspischedda closed 8 months ago

rubenspischedda commented 8 months ago

Hi, I think there could be an error with this line in the buildTagCache() method: https://github.com/TomNCatz/obsidian-gallery/blob/4b3e7dd12d8881540655d31263baf9fa624dd06a/src/main.ts#L357

It attempts to read the property length on undefined. Here is the stacktrace:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
    at GalleryTagsPlugin.buildTagCache (plugin:tagged-gallery:8854:58)
    at GalleryTagsPlugin.buildCaches (plugin:tagged-gallery:8817:14)
    at GalleryTagsPlugin._GalleryTagsPlugin_bootstrap (plugin:tagged-gallery:8900:16)
    at t.onLayoutReady (app.js:1:2006913)
    at GalleryTagsPlugin.onload (plugin:tagged-gallery:8774:28)

It could probably be related to #22, since I couldn't see any images too, and adding the safe navigation operator solved the problem for me:

new Notice(this.propertyCache['artist']?.length.toString());

Now it gives me another error:

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'path')
    at GalleryInfoView.getState (plugin:tagged-gallery-fix:3287:37)
    at t.getViewState (app.js:1:1845798)
    at t.pushUndoHistory (app.js:1:2036610)
    at t.detach (app.js:1:1848686)
    at t.detachLeavesOfType (app.js:1:2026662)
    at GalleryInfoView.closeInfoLeaf (plugin:tagged-gallery-fix:3337:30)
    at GalleryView.onClose (plugin:tagged-gallery-fix:8672:25)
    at GalleryView.<anonymous> (app.js:1:1421862)
    at app.js:1:237544
    at Object.next (app.js:1:237649)
TomNCatz commented 8 months ago

I think you're right, this is sloppy of me, thank you