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

Method execute

src/utils/safeAsync.ts:28–67  ·  view source on GitHub ↗

* Execute an async operation with error handling and user feedback

(
		operation: () => Promise<T>,
		options: {
			fallback?: T;
			errorMessage?: string;
			showNotice?: boolean;
			noticeHandler?: SafeAsyncNoticeHandler;
			logError?: boolean;
		} = {}
	)

Source from the content-addressed store, hash-verified

26 * Execute an async operation with error handling and user feedback
27 */
28 static async execute<T>(
29 operation: () => Promise<T>,
30 options: {
31 fallback?: T;
32 errorMessage?: string;
33 showNotice?: boolean;
34 noticeHandler?: SafeAsyncNoticeHandler;
35 logError?: boolean;
36 } = {}
37 ): Promise<T | undefined> {
38 const {
39 fallback,
40 errorMessage = "An error occurred",
41 showNotice = true,
42 noticeHandler,
43 logError = true,
44 } = options;
45
46 try {
47 return await operation();
48 } catch (error) {
49 if (logError) {
50 tasknotesLogger.error(errorMessage, {
51 category: "provider",
52 operation: "execute-safe-operation",
53 error: error,
54 });
55 }
56
57 if (showNotice) {
58 const message = error instanceof Error ? error.message : String(error);
59 notifyIfRequested(`${errorMessage}: ${message}`, {
60 showNotice,
61 noticeHandler,
62 });
63 }
64
65 return fallback;
66 }
67 }
68
69 /**
70 * Execute an async operation with retry logic

Callers 11

executeWithValidationMethod · 0.95
createTaskFromEventMethod · 0.45
linkExistingNoteMethod · 0.45
executeActionMethod · 0.45
loadRelatedNotesMethod · 0.45
linkExistingNoteMethod · 0.45
createTaskDirectlyMethod · 0.45
refreshRelatedNotesMethod · 0.45
updateStatusBarMethod · 0.45

Calls 2

notifyIfRequestedFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected