MCPcopy
hub / github.com/claude-code-best/claude-code / maybe

Function maybe

src/utils/attachments.ts:1059–1096  ·  view source on GitHub ↗
(label: string, f: () => Promise<A[]>)

Source from the content-addressed store, hash-verified

1057}
1058
1059async function maybe<A>(label: string, f: () => Promise<A[]>): Promise<A[]> {
1060 const startTime = Date.now()
1061 try {
1062 const result = await f()
1063 const duration = Date.now() - startTime
1064 // Log only 5% of events to reduce volume
1065 if (Math.random() < 0.05) {
1066 // jsonStringify(undefined) returns undefined, so .length would throw
1067 const attachmentSizeBytes = result
1068 .filter(a => a !== undefined && a !== null)
1069 .reduce((total, attachment) => {
1070 return total + jsonStringify(attachment).length
1071 }, 0)
1072 logEvent('tengu_attachment_compute_duration', {
1073 label,
1074 duration_ms: duration,
1075 attachment_size_bytes: attachmentSizeBytes,
1076 attachment_count: result.length,
1077 } as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
1078 }
1079 return result
1080 } catch (e) {
1081 const duration = Date.now() - startTime
1082 // Log only 5% of events to reduce volume
1083 if (Math.random() < 0.05) {
1084 logEvent('tengu_attachment_compute_duration', {
1085 label,
1086 duration_ms: duration,
1087 error: true,
1088 } as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS)
1089 }
1090 logError(e)
1091 // For Ant users, log the full error to help with debugging
1092 logAntError(`Attachment error in ${label}`, e)
1093
1094 return []
1095 }
1096}
1097
1098const INLINE_NOTIFICATION_MODES = new Set(['prompt', 'task-notification'])
1099

Callers 1

getAttachmentsFunction · 0.85

Calls 6

fFunction · 0.85
jsonStringifyFunction · 0.85
logEventFunction · 0.85
logAntErrorFunction · 0.85
nowMethod · 0.80
logErrorFunction · 0.70

Tested by

no test coverage detected