chhoumann / MetaEdit

MetaEdit for Obsidian
https://bagerbach.com
GNU General Public License v3.0
393 stars 15 forks source link

[Bug] Console error generated each time a note is modified #62

Closed Elaws closed 2 years ago

Elaws commented 2 years ago

When MetaEdit plugin is activated, console shows the following error each time a note is modified :

Uncaught (in promise) TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at OnFileModifyAutomatorManager.onFileModify (eval at <anonymous> (app.js:1), <anonymous>:5266:29)

I have not encountered any problem linked to this error message, but I would like to know the cause and possibly get rid of it.

Thanks !

willdhorn commented 2 years ago

Also running into this issue. The warning is also only being thrown when the note has no frontmatter

This is the JS where the error is being thrown:

async onFileModify(file) {
        const outfile = abstractFileToMarkdownTFile(file);
        if (!outfile)
            return;
        // Return on Excalidraw files to prevent conflict with its auto-save feature.
        const metadata = await this.app.metadataCache.getFileCache(outfile);
        const keys = Object.keys(metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter);  // <<<< ERROR

And here's the corresponding Typescript: https://github.com/chhoumann/MetaEdit/blob/a835c7932990b8a5ee1350e56312389122109c01/src/automators/onFileModifyAutomatorManager.ts#L56-L62

Putting a simple null check on metadata.frontmatter should fix this.

YIRU69 commented 2 years ago

@willdhorn Can you fix it success? I alse have the error.

YIRU69 commented 2 years ago

When I create a new note, console like this

Uncaught (in promise) TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at OnFileModifyAutomatorManager.onFileModify (eval at <anonymous> (app.js:1:1433712), <anonymous>:5267:23)
chhoumann commented 2 years ago

Hey! I just merged #66 from @ryanjamurphy which fixes this. Thank you for your report!

Elaws commented 1 year ago

@ryanjamurphy : The problem is occurring in Obsidian 1.0.3. Is this expected ?

ryanjamurphy commented 1 year ago

@ryanjamurphy : The problem is occurring in Obsidian 1.0.3. Is this expected ?

I have not seen the error since the fix mentioned above was implemented, and I have been using 1.1 for a week or two.

Elaws commented 1 year ago

@ryanjamurphy : I can confirm the problem is occurring on Obsidian 1.0.3, new vault with only metaedit (I just created a new note, start typing in it and the error regularly occurs) :

image

Maybe Obsidian 1.1 fixes this, I will check once it's released.

EDIT : And apparently, that issue is mentioned here : https://github.com/chhoumann/MetaEdit/issues/72

ksdavidc commented 1 year ago

I am still getting this exact error in version 1.1.9 on mac on every edit.

ryanjamurphy commented 1 year ago

As far as anyone knows, this error occurs because one or more notes linked in the Kanban do not have frontmatter. Set up your notes properly for use with Kanban Board Helper, or, if folks insist on having frontmatter-less notes, someone can try to figure out a better check for null and submit a PR.

Continuing to report the error is fine if that's all you want to do, but it isn't helping anyone.

For context, I have not seen this error for about a year.