Trikzon / obsidian-frontmatter-links

An Obsidian plugin that renders links in a note's frontmatter as links.
MIT License
64 stars 8 forks source link

Weird errors recently #14

Closed thecookiemomma closed 1 year ago

thecookiemomma commented 1 year ago

image On a reload. Also, the quotation marks on the last line of my frontmatter are moving to a new line. Like constantly.

Morekon commented 1 year ago

I also came across this error today. The issue with the new line for quotations did not happen to me though. As I searched for the cause I found that it only happend where a value in the frontmatter had the value null. Further inspection of the code lead to the following conclusion: In the metadata cache you can see in line 15 that it tries to take all keys from the frontmatter. The frontmatter itself must be a Object as defined in line 39. And that is the problem. Line 39 is true for null which leads to a recursive call where frontmatter = null The error then occurs when trying to loop over undefined of Object.keys(null) at line 15. To solve this issue please add a null check at the start of the recursion before the for loop at line 15.

if (frontmatter == null) {
    return;
}

The code of metadata cache: https://github.com/Trikzon/obsidian-frontmatter-links/blob/6c47abb08b8435dd4f26c8fe49517fc179d2a997/src/metadata_cache.ts#L14-L43

Trikzon commented 1 year ago

Hi, thank you for bringing this issue up.

While testing the update I did experience this issue, but extremely rarely, and restarting Obsidian always fixed it and I couldn't reproduce it, so I figured that it was an issue with my code being hot reloaded mid-change by the hot reload plugin (I've gotten many errors because of that and restarting also fixed those).

I won't be able to pay much attention to this project until after December 5 because I have very important finals this week up until then that I need to pay all my attention to.

If you, or someone else, would like to fix the issue with a PR I would be happy to put aside a little bit of time to quickly review it, merge it, and update the plugin to fix the issue. Otherwise, I'm afraid you'll have to disable the "Add to graph" setting until I have time to fix it myself after December 5.

Morekon commented 1 year ago

No problem. I already created a PR to fix it: #15 Btw awesome work so far. I am curious why this is not a native Obsidian thing.

Trikzon commented 1 year ago

I haven't been able to reproduce the error to test if it has been fixed, but assuming @Morekon's fix worked (which I think it would), 1.2.6 should fix this issue.

@thecookiemomma Please make a separate issue about the "On a reload. Also, the quotation marks on the last line of my frontmatter are moving to a new line" issue you are having with a screenshot, please :)