MCPcopy
hub / github.com/callumalpass/tasknotes / deleteTask

Method deleteTask

src/services/TaskService.ts:1542–1606  ·  view source on GitHub ↗

* Delete a task file and remove it from all caches and indexes

(task: TaskInfo)

Source from the content-addressed store, hash-verified

1540 * Delete a task file and remove it from all caches and indexes
1541 */
1542 async deleteTask(task: TaskInfo): Promise<void> {
1543 try {
1544 const file = this.plugin.app.vault.getAbstractFileByPath(task.path);
1545 if (!(file instanceof TFile)) {
1546 throw new Error(`Cannot find task file: ${task.path}`);
1547 }
1548
1549 // Delete from Google Calendar first (before file deletion, so we have the event ID)
1550 if (this.plugin.taskCalendarSyncService && this.hasGoogleCalendarLinks(task)) {
1551 try {
1552 await this.plugin.taskCalendarSyncService.deleteTaskFromCalendarByPath(
1553 task.path,
1554 task.googleCalendarEventId,
1555 task.googleCalendarExceptionEventId
1556 );
1557 } catch (error) {
1558 tasknotesLogger.warn("Failed to delete task from Google Calendar:", {
1559 category: "provider",
1560 operation: "delete-task-google-calendar",
1561 error: error,
1562 });
1563 }
1564 }
1565
1566 // Step 1: Delete the file from the vault
1567 await this.plugin.app.fileManager.trashFile(file);
1568
1569 // Step 2: Remove from cache and indexes (this will be done by the file delete event)
1570 // But we'll also do it proactively to ensure immediate UI updates
1571 this.plugin.cacheManager.clearCacheEntry(task.path);
1572
1573 // Step 3: Emit task deleted event
1574 this.plugin.emitter.trigger(EVENT_TASK_DELETED, {
1575 path: task.path,
1576 deletedTask: task,
1577 });
1578
1579 // Trigger webhook for task deletion
1580 if (this.webhookNotifier) {
1581 try {
1582 await this.webhookNotifier.triggerWebhook("task.deleted", { task });
1583 } catch (error) {
1584 tasknotesLogger.warn("Failed to trigger webhook for task deletion:", {
1585 category: "provider",
1586 operation: "trigger-webhook-task-deletion",
1587 error: error,
1588 });
1589 }
1590 }
1591 } catch (error) {
1592 const errorMessage = error instanceof Error ? error.message : String(error);
1593
1594 tasknotesLogger.error("Error deleting task:", {
1595 category: "persistence",
1596 operation: "deleting-task",
1597 details: {
1598 stack: error instanceof Error ? error.stack : undefined,
1599 taskPath: task.path,

Callers 1

registerTaskToolsMethod · 0.45

Calls 8

getAbstractFileByPathMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80
clearCacheEntryMethod · 0.65
triggerMethod · 0.65
triggerWebhookMethod · 0.65

Tested by

no test coverage detected