liamcain / obsidian-calendar-plugin

Simple calendar widget for Obsidian.
MIT License
1.64k stars 142 forks source link

Open Weekly Note crashes if calendar view hasn't been opened yet #377

Open oowekyala opened 2 weeks ago

oowekyala commented 2 weeks ago

Describe the bug

The command "Open Weekly Note" crashes with "Uncaught TypeError" when the calendar view has not been opened yet.

Steps to reproduce

  1. Open obsidian, do not show the calendar view
  2. Execute "Open Weekly Note" from command palette

Nothing happens but an error is logged in the console:

Uncaught TypeError: Cannot read properties of undefined (reading 'openOrCreateWeeklyNote')
    at Object.checkCallback (plugin:calendar:4419:27)
    at OK (app.js:1:2117643)
    at t.onChooseItem (app.js:1:2726336)
    at t.onChooseSuggestion (app.js:1:1760272)
    at t.selectSuggestion (app.js:1:1759742)
    at e.useSelectedItem (app.js:1:1433276)
    at Object.func (app.js:1:1430675)
    at e.handleKey (app.js:1:754496)
    at e.onKeyEvent (app.js:1:755752)

It's this line: https://github.com/liamcain/obsidian-calendar-plugin/blob/ef3f2696da11aa1d11a272179caea062d6144640/src/main.ts#L63

The view field is undefined and this crashes the function.

Note that you have to start obsidian in such a state that the calendar view is not created on startup (i think). For instance if you open the calendar view then slide the pane out of view, the command works, presumably because the view still exists somewhere. However if you blend out the pane, then shutdown and restart obsidian, then that view is not created on startup.

Expected behavior

Weekly note is opened whether calendar view has been opened or not

Environment (please specify)

OS

Linux

Obsidian Version (e.g. v0.10.6)

(Settings → About → Current Version) v1.7.4

Calendar version 1.5.10

Thank you for this plugin!

ksdavidc commented 14 hours ago

This is due to changes in how views are loaded in latest obsidian. See here https://obsidian.md/changelog/2024-10-16-desktop-v1.7.4/ and here. https://docs.obsidian.md/Plugins/Guides/Understanding+deferred+views

colintedford commented 12 hours ago

I ended up disabling Calendar because of this. I believe it also affects the core Daily Notes plugin because I switched to that and still have Calendar disabled, but I don't remember now.