Skip to content

Commit 99bf78c

Browse files
More UI feedback
1 parent 53281f9 commit 99bf78c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,27 @@ export default class AnkiLink extends Plugin {
5656
}
5757

5858
private async runSyncAndNotify(): Promise<void> {
59+
new Notice("Starting flashcard sync...");
5960
try {
6061
const { added, modified, deleted } = await syncVaultNotes(this.app);
6162
new Notice(
6263
`Synced flashcards.\nAdded ${added} card${added === 1 ? "" : "s"},\nmodified ${modified} card${modified === 1 ? "" : "s"},\ndeleted ${deleted} card${deleted === 1 ? "" : "s"}.`,
6364
);
6465
} catch (error) {
6566
console.error(error);
66-
// TODO: Provide the user with a more helpful error message.
67-
new Notice("Failed to sync flashcards. Check console for details.");
67+
new Notice(`Failed to sync flashcards: ${this.getErrorMessage(error)}`);
6868
}
6969
}
70+
71+
private getErrorMessage(error: unknown): string {
72+
if (error instanceof Error && error.message) {
73+
return error.message;
74+
}
75+
76+
if (typeof error === "string" && error.trim().length > 0) {
77+
return error;
78+
}
79+
80+
return "Unknown error";
81+
}
7082
}

0 commit comments

Comments
 (0)