File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 11- Add LLM guidance (#1736 )
2+ - Fix logger runtime exceptions #(1704)
Original file line number Diff line number Diff line change @@ -52,18 +52,18 @@ export interface LogEntry {
5252}
5353
5454/** @internal */
55- function removeCircular ( obj : any , refs : any [ ] = [ ] ) : any {
55+ function removeCircular ( obj : any , refs : Set < any > = new Set ( ) ) : any {
5656 if ( typeof obj !== "object" || ! obj ) {
5757 return obj ;
5858 }
5959 // If the object defines its own toJSON, prefer that.
60- if ( obj . toJSON ) {
60+ if ( obj . toJSON && typeof obj . toJSON === "function" ) {
6161 return obj . toJSON ( ) ;
6262 }
63- if ( refs . includes ( obj ) ) {
63+ if ( refs . has ( obj ) ) {
6464 return "[Circular]" ;
6565 } else {
66- refs . push ( obj ) ;
66+ refs . add ( obj ) ;
6767 }
6868 let returnObj : any ;
6969 if ( Array . isArray ( obj ) ) {
@@ -72,13 +72,21 @@ function removeCircular(obj: any, refs: any[] = []): any {
7272 returnObj = { } ;
7373 }
7474 for ( const k in obj ) {
75- if ( refs . includes ( obj [ k ] ) ) {
76- returnObj [ k ] = "[Circular]" ;
75+ if ( obj . hasOwnProperty ( k ) ) {
76+ try {
77+ if ( refs . has ( obj [ k ] ) ) {
78+ returnObj [ k ] = "[Circular]" ;
79+ } else {
80+ returnObj [ k ] = removeCircular ( obj [ k ] , refs ) ;
81+ }
82+ } catch {
83+ returnObj [ k ] = "[Error - cannot serialize]" ;
84+ }
7785 } else {
78- returnObj [ k ] = removeCircular ( obj [ k ] , refs ) ;
86+ returnObj [ k ] = "[Error - defined in the prototype but missing in the object]" ;
7987 }
8088 }
81- refs . pop ( ) ;
89+ refs . delete ( obj ) ;
8290 return returnObj ;
8391}
8492
You can’t perform that action at this time.
0 commit comments