reuseman/flashcards-obsidian

Give an error message when there is an invalid ID

hf02 opened this issue · 4 comments

hf02 commented

Is your feature request related to a problem? Please describe.
Somewhere in my notes I have an invalid ID. I have no idea which one, and the console gave a cryptic error, so I assumed it was a bug and made #176.

Describe the solution you'd like
An error message saying which ID is invalid, so I can CTRL + F it and remove it.

Describe alternatives you've considered
Going one by one to find the invalid ID, or nuking the note and having it regenerate everything.

I'm digging into why this is happening to me too, and it seems that I've deleted a note from Anki. Therefore the plugin cannot find the note matching one of the IDs from my file in Obsidian.

I'm not sure what the expected behavior would be in this case. Maybe also delete the note from Obsidian?

There actually is something here that should output a nice error message when a card is not present in Anki:

      if (cardsNotInAnki) {
        console.info("Flashcards: Cards not in Anki (maybe deleted)");
        for (const card of cardsNotInAnki) {
          this.notifications.push(
            `Error: Card with ID ${card.id} is not in Anki!`
          );
        }
      }

But apparently that doesn't work

The __init__() missing 3 required positional arguments: 'help_page', 'context', and 'backtrace' error actually comes from Anki via reject(e) in anki.ts. So this might be something we'd need to pick up with the developer of the AnkiConnect Anki plugin...

Or maybe we could do findNotes and compare the received list with what we have in Obsidian, and then only run notesInfo for the existing notes

Edit: That was easier than expected, see PR #182