diff --git a/src/data/models/book.ts b/src/data/models/book.ts index 7c8cbb3..9490558 100644 --- a/src/data/models/book.ts +++ b/src/data/models/book.ts @@ -201,7 +201,12 @@ export class Book implements frontbook { async initialize() { this.name = getParentFolderName(this.flashcardsPath); this.parsedCards = await parseFileText(this.flashcardsPath); - this.flashcards = generateFlashcardsArray(this.parsedCards); + try { + this.flashcards = generateFlashcardsArray(this.parsedCards); + } catch (e) { + console.error(e); + throw new Error("initialize: You have invalid flashcards in your file."); + } const annotationTFile = getAnnotationFilePath(this.flashcardsPath); if (annotationTFile) { this.annotationPath = annotationTFile.path; diff --git a/src/ui/modals/flashcard-modal.tsx b/src/ui/modals/flashcard-modal.tsx index 24b723d..b7dc814 100644 --- a/src/ui/modals/flashcard-modal.tsx +++ b/src/ui/modals/flashcard-modal.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Modal } from "obsidian"; +import { Modal, Notice } from "obsidian"; import type SRPlugin from "src/main"; import { createRoot, Root as ReactDomRoot } from "react-dom/client"; import { createMemoryRouter, RouterProvider } from "react-router-dom"; @@ -71,7 +71,13 @@ export async function init() { // done: fix const notesWithFlashcards = filePaths.map((t: string) => new Book(t)); for (const t of notesWithFlashcards) { - await t.initialize(); + try { + await t.initialize(); + } catch (e) { + console.error(e); + console.error("init: unable to initialize book"); + new Notice("Error: Unable to parse legacy SRS flashcards. Try removing the #flashcards tag from files with SRS flashcards."); + } } return notesWithFlashcards; } \ No newline at end of file