franciskafieh / obsidian-list-modified

🪨 The advanced and adaptive changelog for Obsidian. Links all modified files meeting certain criteria to a timed (daily, weekly, monthly) note.
MIT License
85 stars 7 forks source link

[BUG] Appending to wrong note #87

Open joh6nn opened 8 months ago

joh6nn commented 8 months ago

First Steps

Describe the bug

Links are consistently added to the incorrect note. I've got a vault with the following structure:

|-Entries
| \- [...Several Years of Daily Notes with the folder structure below]
| \- 2023
|    \ - 10 Oct
|        |- [Daily notes for Oct]
|        |- 18.md
|-Notes
|-Templates

Today, I enabled List Modified, with the following settings:

Instead of appending the links to the Notes heading in file Entries/2023/10 Oct/18.md , the links are being appended to Entries/2021/09 Sep/18.md

Expected behaviour

What should happen instead?

links should be appended to the Notes heading in file Entries/2023/10 Oct/18.md

Reproducing

My setup

image

Steps to reproduce bug

Can you pinpoint when/why this bug happens?

n/a

franciskafieh commented 8 months ago

Could you please send me your output file configuration? Basically, just the rest of your settings pane works.

joh6nn commented 8 months ago

image

Ignored Tags is empty.

If you need anything else, just let me know :slightly_smiling_face:

franciskafieh commented 8 months ago

Would you mind sending me this part?

image

joh6nn commented 8 months ago

Unless I'm missing something, that's in the original screenshot?

Output Format is - ![[link]] Time Format is unset because I'm not using a time field Append Space After Headings is off

franciskafieh commented 8 months ago

You’re right, my bad.

franciskafieh commented 8 months ago

Sorry, misclick on mobile, lol. I’ll take a look in a few hours

franciskafieh commented 8 months ago

Alright, last thing: your Daily Notes settings pane, or your Periodic Notes settings if using that plugin

Just want to make sure that's setup properly. If it is, I will need to release a test version to help solve this. It seems to be working fine on my machine.

joh6nn commented 8 months ago

image

joh6nn commented 8 months ago

I do have a bunch of plugins, and I'm more than open to the idea that one or more of them is conflicting, I just don't know which one(s), or how to go about figuring that out (short of very tediously disabling all of them, and then turning them on one at a time. Which I'd love to not have to do)

franciskafieh commented 8 months ago

image I mirrored your daily notes and file name settings here exactly, and everything works fine for me. Could you do the following for me?

  1. open the developer console (ctrl/cmd + shift + i)
  2. type clear() in the prompt area at the bottom
  3. screenshot the output (any errors, warnings, etc, should display)
joh6nn commented 8 months ago

image

I checked to see if there's any additional info if I bump the console output up to Verbose, but there's not, just the Obsidian Git plugin spamming the console with "task complete" messages.

franciskafieh commented 8 months ago

I think I’m going to add a debug mode to the plugin. I’ve been meaning to make one for awhile now. I’ll try to get it out tomorrow and we’ll see if it helps. In the mean time, you could try a different vault with just Obsidian List Modified, maybe? If it works there and not in your normal vault, it’s most likely a conflicting plugin

joh6nn commented 8 months ago

Ok, so current situation is super weird:

I tried disabling plugins in this vault in a binary search (ie, I disabled half of them and tested, then disabled half of what was left and tested, and so on), and got down to the only plugin still enabled is List Modified, and I'm still seeing the incorrect behavior.

So I created a new vault, enabled Daily Notes, installed List Modified, and tried to recreate the issue by creating a note for today (2023-10-22), and also creating a note for 2021-09-22. I was able to reproduce the issue twice, but I can't reproduce it consistently. I don't know what was different about the two times I got it to happen.

If you add the debug mode, I'll try to collect more info

franciskafieh commented 8 months ago

That’s super odd.. I’ll try to get debug mode out ASAP. I’ve got a pretty bad flu right now though

By any chance, was SyncThing enabled on your second vault, too? I’m wondering if that could be the issue, but honestly, I can’t see how Sync would affect the output file’s location

joh6nn commented 8 months ago

Nope, no SyncThing 🤷

Sorry to hear about the flu, hope you feel better soon!

franciskafieh commented 8 months ago

Sorry for the long delay. I'm about to publish it as a pre-release, which means you will need to use the BRAT plugin or manually install it (video here if you need help).

What you're mainly looking for is this part... image

After you've enabled the verbose mode setting, you should be able to open the dev console as you have done before. Play around with editing files, etc, until you see a message like that or "Log note not found, but should be created automatically. Creating now..."

franciskafieh commented 8 months ago

Link to pre-release: https://github.com/franciskafieh/obsidian-list-modified/releases/tag/2.2.1

joh6nn commented 8 months ago

Ok, I made a copy of my vault, and installed 2.2.1 with BRAT:

plugin:obsidian-list-modified:938 OLM settings saved.
plugin:obsidian-list-modified:790 --- Writing tracked files ---
plugin:obsidian-list-modified:744 [Obsidian List Modified] Log note found at: Entries/1999/12/31.md

Then I created a brand new empty vault, installed only BRAT and OLM, configured Daily Note to match my real vault (as noted above), and made a Templates folder, an Entries folder, and a Notes folder. I clicked the Daily Note button in the ribbon to create a daily note from the template, and then created two files in Notes, and OLM correctly added them to today's note.

Then I created Entries/2021/09/31.md. I closed and re-opened the test vault, and created a new file in Notes, and bingo: it added the list to the incorrect note, with all 3 entries (the one from just now, and the 2 from before):

image

franciskafieh commented 8 months ago

that’s super weird.. It seems like moment.js thinks the current year is 2021, or it may be a bug in the upstream plugin I’m using to get daily notes.. I’m gonna need to add something to the debug mode. I’ll try to get it done within a few hours

On Tue, Oct 31, 2023 at 5:25 PM joh6nn @.***> wrote:

Ok, I made a copy of my vault, and installed 2.2.1 with BRAT:

plugin:obsidian-list-modified:938 OLM settings saved. plugin:obsidian-list-modified:790 --- Writing tracked files --- plugin:obsidian-list-modified:744 [Obsidian List Modified] Log note found at: Entries/1999/12/31.md

Then I created a brand new empty vault, installed only BRAT and OLM, configured Daily Note to match my real vault (as noted above), and made a Templates folder, an Entries folder, and a Notes folder. I clicked the Daily Note button in the ribbon to create a daily note from the template, and then created two files in Notes, and OLM correctly added them to today's note.

Then I created Entries/2021/09/31.md. I closed and re-opened the test vault, and created a new file in Notes, and bingo: it added the list to the incorrect note, with all 3 entries (the one from just now, and the 2 from before):

[image: image] https://user-images.githubusercontent.com/1129329/279519064-b391947a-ba7d-42c5-abc2-49c66a631f97.png

— Reply to this email directly, view it on GitHub https://github.com/franciskafieh/obsidian-list-modified/issues/87#issuecomment-1788059442, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWLR3ZU6OZVHD4U3VI5EHSLYCFUFRAVCNFSM6AAAAAA6F5AY72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBYGA2TSNBUGI . You are receiving this because you modified the open/close state.Message ID: @.***>

joh6nn commented 8 months ago

My initial guess here is that the upstream plugin has a bug, because it also incorrectly detected 1999 as the current year, and additionally it also incorrectly detects the current month. I feel like moment.js has enough users that if it was the source of the bug, someone would have noticed :slightly_smiling_face:

joh6nn commented 8 months ago

Yup, confirmed: https://github.com/liamcain/obsidian-daily-notes-interface/issues/21

It's been broken for directory structures like YYYY/MM/DDD and similar for a long time, it seems.

franciskafieh commented 8 months ago

good detective work lol. super weird since it was working for me… since it seems like a lot of people want it fixed but nobodys taken a shot at it, I could try forking the plugin and figuring it out

On Tue, Oct 31, 2023 at 6:17 PM joh6nn @.***> wrote:

Yup, confirmed: liamcain/obsidian-daily-notes-interface#21 https://github.com/liamcain/obsidian-daily-notes-interface/issues/21

It's been broken for directory structures like YYYY/MM/DDD and similar for a long time, it seems.

— Reply to this email directly, view it on GitHub https://github.com/franciskafieh/obsidian-list-modified/issues/87#issuecomment-1788112265, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWLR3ZTWVBWABADKA5WW663YCF2G3AVCNFSM6AAAAAA6F5AY72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBYGEYTEMRWGU . You are receiving this because you modified the open/close state.Message ID: @.***>

joh6nn commented 8 months ago

It looks like there's actually a PR that claims to fix it: https://github.com/liamcain/obsidian-daily-notes-interface/pull/25

It's actually fixing a bug in one of the developer's other plugins (the Calendar plugin), but the underlying issue is the same.

I still haven't really wrapped my head around modern JS's functional stuff, but it looks reasonable to me? I think it's dynamically building a RegEx that matches whatever the Daily/Periodic note settings currently are, but I gladly defer to you here

franciskafieh commented 8 months ago

Looks good and for sure lol. Appreciate you for putting effort into the bug too. Sorry I’m not being very helpful, on mobile rn. I’ll change the plugin to depend on that fork and release it in a few hours. Hopefully that will help

On Tue, Oct 31, 2023 at 6:31 PM joh6nn @.***> wrote:

It looks like there's actually a PR that claims to fix it: liamcain/obsidian-daily-notes-interface#25 https://github.com/liamcain/obsidian-daily-notes-interface/pull/25

It's actually fixing a bug in one of the developer's other plugins (the Calendar plugin), but the underlying issue is the same.

I still haven't really wrapped my head around modern JS's functional stuff, but it looks reasonable to me? I think it's dynamically building a RegEx that matches whatever the Daily/Periodic note settings currently are, but I gladly defer to you here

— Reply to this email directly, view it on GitHub https://github.com/franciskafieh/obsidian-list-modified/issues/87#issuecomment-1788124111, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWLR3ZSTJ7PWC63EI54ECYDYCF33HAVCNFSM6AAAAAA6F5AY72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBYGEZDIMJRGE . You are receiving this because you modified the open/close state.Message ID: @.***>

joh6nn commented 8 months ago

No worries! You've been super responsive as far as I'm concerned. Also, you're working for free; I'm grateful that you shared your work to begin with! Me putting in the legwork to make a decent bug report is the least I can do :slightly_smiling_face:

franciskafieh commented 8 months ago

I'll need to work on this tomorrow as adding this fork as a dependency is way harder than it should be. Sorry for the delay

franciskafieh commented 8 months ago

try release 2.2.2 for me on BRAT. See if that fixes it

joh6nn commented 8 months ago

Ok, one step forward, one step back:

Recounting all my steps in case it's relevant.

I usually leave Obsidian open in the background, so both my main vault and the from-scratch test vault were still running from the other night. I upgraded OLM in the from-scratch vault, closed it, and reopened it by clicking on the vault icon in the window for my main vault.

As expected, it automatically created a new daily, and OLM correctly identified the Daily Note! But: it incorrectly identified what files to list there: I had only just opened the vault, and not created or modified any other files, so there shouldn't have been any files to list. Instead, it listed all 3 files from the notes folder. Both Obsidian and my file browser show the last modified time as Oct 31 for all 3 files :shrug:

image

franciskafieh commented 8 months ago

When the console says File created in that screenshot, what file was created? Would you mind sending me your data.json as well? I don't see how this bug could occur, as the logic is pretty straightforward and shouldn't be affected by the daily note location bug

    if (!lastTrackedDate.isSame(moment(), granularity)) {
        displayNotice(
            "New day/week/month detected, writing tracked files and resetting..."
        );
        await saveSettingsAndWriteTrackedFiles();

        // this code resets the tracked files in data.json and saves the files
        settings.trackedFiles = [];

        // current date as known by moment, should not be affected by file path bug
        settings.lastTrackedDate = moment().format("YYYY-MM-DD");
        await saveSettings();
    }
franciskafieh commented 8 months ago

Edit: this reminds me to add some more specific things to the verbose mode

joh6nn commented 8 months ago

The file that was created was the the one with focus in Obsidian: 2023/11 Nov/02.md

Here's my data.json. I glanced at it real quick before uploading, and remembered: I turned off "auto create log note", which is reflected in the json. So either there's a bug in the verbose output and it's writing that to the console when it shouldn't, or there's a bug in the automatic file creation logic and it's running when it shouldn't data.json

franciskafieh commented 8 months ago

Did you edit the data.json at all? It shows no files in the trackedFiles array, so nothing should be written to your daily note... Super odd. Everything is working fine on my end (tracking the right files, note not being created automatically unless told to, etc). If there were problems with this, there would be many other issues open.

This didn't happen before the update, right? I don't see how these changes would affect any of this anyway.

Could you delete the data.json to give OLM a fresh start? Then, enable verbose mode again. Now it shows the names of created files and stuff as well. I'm honestly super confused since usually I know what I'm doing with my own plugin lol

franciskafieh commented 8 months ago

Oh wait, the issues with create are my fault. Verbose mode outputs "file created" even if it is not added to data.json (it's filtered out for one reason or another)

As per identifying the right files to modify, I could try adding even more test messages to see why each file is identified. But this shouldn't be necessary, and I don't know why you're getting the wrong list of files when the data.json shows no files at all.

Maybe try deleting it for now (as I said above) and see what happens

joh6nn commented 8 months ago

Sigh. Ok, I apologize, because I feel like I'm taking you down a rabbit hole here:

So to make sure that I hadn't unintentionally messed anything up or introduced any weirdness in the previous round of testing, I deleted my test vault and recreated it.

Like before, I was able to reproduce the issue one time, but I'm not clear on how :slightly_frowning_face:. And now I can't reproduce it again.

But while I was trying, I got OLM to insert the list of modified files to the same note twice in a single session. So naturally I wanted to see "what happens when I make a new note now?" and the answer was that it figured out that the list should only be added to the Log Note one time, but it deleted all the content in the note after the note heading :shrug:

franciskafieh commented 8 months ago

Don't apologize!

and the answer was that it figured out that the list should only be added to the Log Note one time

I think it does this sometimes, but tmk it's a concurrency issue which is pretty difficult to fix without extra reads to the file and complication. As long as it solves itself, it should be fine in my books

but it deleted all the content in the note after the note heading

this shouldn't happen. Do you think what you're describing is related to #81? I need to fix that soon anyway

joh6nn commented 7 months ago

Yeah, that looks like it's either the same issue, or very closely related

franciskafieh commented 7 months ago

81 should be fixed now. try it out and let me know what happens :)

franciskafieh commented 7 months ago

Nevermind, one second

franciskafieh commented 7 months ago

Should be good now

franciskafieh commented 7 months ago

Any updates? Going to close if this issue is fixed

joh6nn commented 7 months ago

Hey, sorry for the radio silence, I have been crazy busy the last several weeks and haven't had time to give this the attention it deserves. I'm hoping to get to it this weekend

franciskafieh commented 7 months ago

No worries

joh6nn commented 7 months ago

so, apologies for the long delay in getting back to this

So, good news, bad news, good news.

Good news: as far as I can tell the initial issue that I opened this ticket for is fixed: in all my testing, OLM now successfully writes to the correct note.

Bad news: I'm still seeing issues with symptoms similar to #81 , where content after the insertion is being overwritten/erased.

Good news: I can consistently reproduce it!

  1. Open the vault, let Obsidian automatically create the daily note
  2. manually create a new note
  3. delete the daily note
  4. close Obsidian, and reopen it, and let it automatically recreate the daily note
  5. manually create a new note
  6. et voila! everything after the inserted content is missing

Also fun: sometimes the inserted content is duplicated. Sometimes it's duplicated in its entirety, and sometimes only one or two lines are duplicated. It doesn't appear to be a rendering issue; opening a different note, and then coming back to the daily note, the duplicated content is still there. I can reproduce this frequently, but haven't figured out specific steps for reproducing it consistently. It's not clear to me whether this is related to the symptoms of #81, or if it's a separate issue

Since the original issue is now solved, do you want to move these other symptoms to a new issue (or issues?)

joh6nn commented 6 months ago

Hey, happy new year! Hope your holidays were good. Just wanted to check back in on this

franciskafieh commented 5 months ago

Sorry, I missed the original notification. I’m still on vacation so I don’t have access to my computer right now. I’ll try to work on this asap. Thanks for following up

On Tue, Jan 2, 2024 at 8:46 PM joh6nn @.***> wrote:

Hey, happy new year! Hope your holidays were good. Just wanted to check back in on this

— Reply to this email directly, view it on GitHub https://github.com/franciskafieh/obsidian-list-modified/issues/87#issuecomment-1874758328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWLR3ZX5UYHQ45K7DI3ZG4DYMSZ77AVCNFSM6AAAAAA6F5AY72VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZUG42TQMZSHA . You are receiving this because you modified the open/close state.Message ID: @.***>

joh6nn commented 5 months ago

No worries, and no rush; enjoy your vacation!

franciskafieh commented 4 months ago

Sorry for the wait. After my break I had exams. Everything's done now, so I'm back to working on the plugin.

joh6nn commented 4 months ago

No worries: our lives have to come before our projects! I hope you did well on your exams 🤞

franciskafieh commented 4 months ago

90 would fix this as it would be way more reliable than headings. Just want to see everyone's opinions before making the breaking change

franciskafieh commented 4 days ago

This has been dead for awhile, but I'm back to working on it. What's super odd is that the local "fork" of the upstream plugin that was causing the bug is exactly the same as the published version. Basically, I forgot to download the "patch" branch instead of the default. And somehow, your issue is still fixed? I'm trying to replicate it right now with the same daily note format as you, and everything seems good. Super odd. I guess I will just leave it as is for now.... I'm stumped

Edit: Talking about the "finding the daily note" bug, not the heading bug, which will definitely be fixed in 3.0. Also, the supposed patch PR won't even build. The contributor messed something up and I haven't had a chance to look into it.