Skip to content

Commit b6706a9

Browse files
committed
Surface API errors to users in notifications
Show meaningful error messages when tagging fails instead of silently logging to console.
1 parent 8eb56cf commit b6706a9

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/main.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,22 @@ export default class AITaggerPlugin extends Plugin {
186186
);
187187

188188
// Final notice with completion message
189-
notification.setSuccess(
190-
`Completed tagging ${result.successful}/${result.total} notes successfully`
191-
);
189+
if (result.failed > 0 && result.successful === 0) {
190+
// All notes failed - show error with details
191+
notification.setError(
192+
`Failed to tag all ${result.total} notes.\n${result.lastError || "Unknown error"}`
193+
);
194+
} else if (result.failed > 0) {
195+
// Some notes failed - show mixed result
196+
notification.setError(
197+
`Tagged ${result.successful}/${result.total} notes. ${result.failed} failed.\n${result.lastError || ""}`
198+
);
199+
} else {
200+
// All notes succeeded
201+
notification.setSuccess(
202+
`Completed tagging ${result.successful}/${result.total} notes successfully`
203+
);
204+
}
192205
} catch (error) {
193206
console.error("Error during bulk tagging:", error);
194207
const errorMessage =

src/services/noteService.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,32 @@ export async function tagAllNotes(
6161
app: App,
6262
settings: AITaggerSettings,
6363
progressCallback?: (processed: number, successful: number, total: number, currentFile: string) => void
64-
): Promise<{ successful: number, total: number }> {
64+
): Promise<{ successful: number, total: number, failed: number, lastError?: string }> {
6565
const files = app.vault.getMarkdownFiles();
6666
let processed = 0;
6767
let successful = 0;
68+
let failed = 0;
69+
let lastError: string | undefined;
6870

6971
for (const file of files) {
7072
try {
7173
// Report progress if callback is provided
7274
if (progressCallback) {
7375
progressCallback(processed, successful, files.length, file.path);
7476
}
75-
77+
7678
const content = await app.vault.read(file);
7779
const tags = await generateTags(content, settings);
7880
await updateNoteFrontmatter(app, file, tags);
7981
successful++;
8082
} catch (error) {
8183
console.error(`Error tagging note ${file.path}:`, error);
84+
failed++;
85+
lastError = error instanceof Error ? error.message : String(error);
8286
}
8387

8488
processed++;
8589
}
8690

87-
return { successful, total: files.length };
91+
return { successful, total: files.length, failed, lastError };
8892
}

0 commit comments

Comments
 (0)