File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,23 @@ const analyticsDispatcher = createAnalyticsDispatcher({
3838 bufferWhenNoUser : true ,
3939} )
4040
41+ /**
42+ * Safely stringify an object, handling circular references.
43+ * Replaces circular references with '[Circular]' placeholder.
44+ */
45+ function safeStringify ( obj : unknown ) : string {
46+ const seen = new WeakSet ( )
47+ return JSON . stringify ( obj , ( _key , value ) => {
48+ if ( typeof value === 'object' && value !== null ) {
49+ if ( seen . has ( value ) ) {
50+ return '[Circular]'
51+ }
52+ seen . add ( value )
53+ }
54+ return value
55+ } )
56+ }
57+
4158function isEmptyObject ( value : any ) : boolean {
4259 return (
4360 value != null &&
@@ -163,7 +180,7 @@ function sendAnalyticsAndLog(
163180 // In dev mode, use appendFileSync for real-time logging (Bun has issues with pino sync)
164181 // In prod mode, use pino for better performance
165182 if ( IS_DEV && logPath ) {
166- const logEntry = JSON . stringify ( {
183+ const logEntry = safeStringify ( {
167184 level : level . toUpperCase ( ) ,
168185 timestamp : new Date ( ) . toISOString ( ) ,
169186 ...loggerContext ,
You can’t perform that action at this time.
0 commit comments