obsidian-periodic-notes
obsidian-periodic-notes copied to clipboard
Failed to create file when trying to open weekly note
So... This is weird, especially after taking a look at the code both in this repo and obsidian-daily-notes-interface
.
Whenever I create a weekly note for the first time, everything works as expected. It creates the note in my designated location, and opens it in the editor. However, when I move to another note and invoke the Periodic Notes: Open weekly note
command via the command palette, I get the following error in the console:
Failed to create file: 'Journal/Weekly Reviews/2021-W30.md' Error: File already exists.
Which... makes sense. Because the file already exists. But I expected it to just open the weekly note, just like how it works for the daily notes. These are the settings that I'm using at the moment.
The only thing I could think of is it being an issue with the "escape characters" used in the Format
. I could imagine that the code checks if the file exists (to already open it) is somehow "fooled" when using a character like this, and that would always return false
. At the same time though, I tried running window.app.vault.create("Journal/Weekly Reviews/2021-W30.md");
manually from the console, but got the same error. So I'm kind of lost here. Hope you can help me out! 😄
I'm having the same problem. Doesn't seem to matter what format is used though. It also seems like this issue extends to the Calendar plugin as well where the weekly note isn't recognized or accessible through the calendar widget.
EDIT: As suggested by Liam on the discord - you just need to chance "WW" to "ww" in the file format to fix it!
Thanks for confirming the issue @MarkQueppet! However, changing WW
to ww
doesn't actually solve it; I want to use the ISO-week notation 😕
Should I open an issue/thread on the Obsidian Forum about this, @liamcain? Having seen the underlying code it looks like this isn't an issue with this plugin, but instead with Obsidian itself. What do you think?
(Possibly related to this whole web of weird issues: https://github.com/liamcain/obsidian-periodic-notes/issues/56#issuecomment-906579292)
Thanks for confirming the issue @MarkQueppet! However, changing
WW
toww
doesn't actually solve it; I want to use the ISO-week notation 😕
I think it's an issue by mixing ISO and non-ISO week and year notations. I am now using GGGG-[W]WW and no longer have the issue in #56 .
Good call @zenodotus280. I just tried using GGGG-[W]WW
, but it still gives me the error "Unable to create new file". I'm at a loss here, this is super confusing.
This issue happens because the start of the ISO week should be on Monday, but the default is Sunday. Periodic Notes checks if you have a note for the current week, sees that you do not, takes the start of the current week (incorrectly, previous Sunday) and tries to create the file that corresponds to that ISO week. This fails because the file already exists.
The correct solution would be to use isoWeek
as the unit of time in const startOfPeriod = date.clone().startOf(config.unitOfTime)
in the openPeriodicNote function if the week format is WW. Or just to skip the "take the start of the current week" step.
A workaround that seems to work for me is to install the "Calendar" plugin by the same author (https://github.com/liamcain/obsidian-calendar-plugin) and set the "Start week on" option to Monday. This seems to override the default and I don't get errors.
@urdvr you're absolutely right! Installing the Calendar plugin and setting the "Start week on"-setting to "Monday" does indeed fix the issue. Thanks for your detective work, I couldn't spot that issue you described but it totally makes sense as to why it's messing up now.
I'll leave this issue open if we want to track the bug here, but in the meantime I'll work around it by just keeping the Calendar plugin installed.
I had the same problem and developed a workaround.
Installing the Calendar plugin did not work for me (Obsidian v0.13.23, Periodic Notes v0.0.17). The Calendar plugin has been fully deprecated at this point. Further, the "Start week on" setting is no longer present in the Calendar plugin options.
I am using my system locale of "en" on a Windows machine. Windows is set to use start of week Monday (under regional format settings). My weekly note filename format is gggg-[W]WW
(ISO weeknum), but I get the same error "Failed to create weekly note" (because it already exists).
After reviewing the code in .obsidian/plugins/periodic-notes/main.js
and the documentation for Moment.js I confirmed it was a locale issue. Specifically, that getDateUID
is backing into a string representation for the week start from the current date.
As a workaround, I can globally update my locale to my ISO week settings at the top of main.js
by adding:
// ISO-8601, Europe
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
doy: 4 // First week of year must contain 4 January (7 + 1 - 4)
}});
after the DEFAULT const declarations (around line 15). Saving the updated script and reloading Obsidian solves my weekly note command. This workaround would be lost after the next plugin update though.
As a more permanent fix, I might suggest changing the getWeeklyNote
function to convert the date into the expected note path (using the logic in createWeeklyNote
) instead of calculating the date UID key that the getAllWeeklyNotes
dictionary uses.