obsidian-google-calendar
obsidian-google-calendar copied to clipboard
[BUG] app.js:1 Uncaught (in promise) Error: File already exists.
I get quite a lot of those when using autocreate. It kinda seems like the plugin tries to create an event note that already exists. This seems to crash the whole import, so when 8 events need to be imported and the second crashes, after that no further are created. Also every further import crashes instantly because now it's the first in queue.
I could not yet pin down what part of a file makes this error appear. I have some events where this never happens and some where it always happens. When I delete those event notes, the next import runs through completely fine, every following one crashes at those notes again. Tose breaking notes/events do not seem to have any special format or stuff. No weird characters (all alphanumerical + underscore & space), no special handling. Happens also when templater is disabled on file creation and when the templates used are empty too. The very exact same configuration (same string in google description, so same folder and template) works on other notes. The breaking event note is not found when it consist of only one frontmatter line (so 3 lines total) with the event-id. The id is also constant on every import and seems legit.
File pattern is: {{event-date}}_{{prefix}}{{event-title}}
Prefi is: E_
Maybe the Event-Note search could be hardened or this error could just be catched? Since the notes that crash the import are already successfully imported at this point, it would be completely sufficient to just continue with the next item in queue. The initial creation works flawlessly. It's just that the import is broken as soon as those problematic notes exist.
Hi @Bjaux, your contribution looks good, but only patches the problem. I will merge it, but we should keep this issue open and as you already said, harden the search.
The {{prefix}}
is supposed to be the prefix. It has to be the first thing in the file name, like this.
{{prefix}}{{event-date}}_{{event-title}}
.
I will add a check in the settings to make sure it is used right.
Its purpose is mainly to increase the performance when checking the notes for the event-id
const filesWithName = app.vault.getFiles().filter(file =>
file.basename.startsWith(plugin.settings.optionalNotePrefix)
)
Hey @YukiGasai , a prefix as a prefix, how revolutionary. I had hoped that just having that string included in the file name would already speed the search up. I could absolutely deal with a real prefix, but had my event notes starting with their respective date and hoped to just keep that. Thanks for that insight!
Some small thoughts from me where I might be mistaken since I am very new to this codebase:
- i got the impression the
findEventNoteByTitle
-Function inside Helper.ts might benefit from using the filename that applying the Event Note Name Format would yield, if that's the name under which it would create an imported event note? - Wouldn't it then make sense for the
createNoteFromEvent
-Function inside AutoEventNoteCreator.ts to make it's check inside//check if file already exists
with thefindEventNote
-Function from Helper.ts to be very sure that no matter where a note for this event is there is no duplicate created (or attempted)? - And if the
vault.create(filePath, '');
-call insidecreateNoteFromEvent
in AutoEventNoteCreator is crashing the whole import if it fails, maybe safeguard it so that the other files continue? (even though - if we do check for a note to exist at that exact file path, it should be quite safe - but maybe if there is a note that doesn't have the event-id and thus wouldn't be returned byfindEventNote
?)
Thank you any way for your fast reaction, like I said, I really appreciate this plugin and your great work! :)