MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / initializeWarningHandler

Function initializeWarningHandler

source code/utils/warningHandler.ts:62–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62export function initializeWarningHandler(): void {
63 // Only set up handler once - check if our handler is already installed
64 const currentListeners = process.listeners('warning')
65 if (warningHandler && currentListeners.includes(warningHandler)) {
66 return
67 }
68
69 // For external users, remove default Node.js handler to suppress stderr output
70 // For internal users, only keep default warnings for development builds
71 // Check development mode directly to avoid async call in init
72 // This preserves the same logic as getCurrentInstallationType() without async
73 const isDevelopment =
74 process.env.NODE_ENV === 'development' || isRunningFromBuildDirectory()
75 if (!isDevelopment) {
76 process.removeAllListeners('warning')
77 }
78
79 // Create and store our warning handler
80 warningHandler = (warning: Error) => {
81 try {
82 const warningKey = `${warning.name}: ${warning.message.slice(0, 50)}`
83 const count = warningCounts.get(warningKey) || 0
84
85 // Bound the map to prevent unbounded memory growth from unique warning keys.
86 // Once the cap is reached, new unique keys are not tracked — their
87 // occurrence_count will always be reported as 1 in analytics.
88 if (
89 warningCounts.has(warningKey) ||
90 warningCounts.size < MAX_WARNING_KEYS
91 ) {
92 warningCounts.set(warningKey, count + 1)
93 }
94
95 const isInternal = isInternalWarning(warning)
96
97 // Always log to Statsig for monitoring
98 // Include full details for ant users only, since they may contain code or filepaths
99 logEvent('tengu_node_warning', {
100 is_internal: isInternal ? 1 : 0,
101 occurrence_count: count + 1,
102 classname:
103 warning.name as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
104 ...(process.env.USER_TYPE === 'ant' && {
105 message:
106 warning.message as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
107 }),
108 })
109
110 // In debug mode, show all warnings with context
111 if (isEnvTruthy(process.env.CLAUDE_DEBUG)) {
112 const prefix = isInternal ? '[Internal Warning]' : '[Warning]'
113 logForDebugging(`${prefix} ${warning.toString()}`, { level: 'warn' })
114 }
115 // Hide all warnings from users - they are only logged to Statsig for monitoring
116 } catch {
117 // Fail silently - we don't want the warning handler to cause issues
118 }
119 }

Callers 1

mainFunction · 0.85

Calls 9

isInternalWarningFunction · 0.85
logEventFunction · 0.85
isEnvTruthyFunction · 0.85
logForDebuggingFunction · 0.85
setMethod · 0.80
toStringMethod · 0.65
getMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected