Skip to content

Commit

Permalink
fix: add error handling logic for legacy flashcards
Browse files Browse the repository at this point in the history
- Fixes #1
  • Loading branch information
AB1908 committed Sep 9, 2023
1 parent 349c130 commit dd74032
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/data/models/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/ui/modals/flashcard-modal.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}

0 comments on commit dd74032

Please sign in to comment.