Skip to content

Commit 4559866

Browse files
authored
fix(logger): no longer detects duplicate object as circular (#1679)
* fix(logger): no longer detects duplicate object as circular * perf(logger): improved performance of circular removal * chore(logger): changes due to lint * perf(logger): nvm, the original is probably more efficient
1 parent e3f9772 commit 4559866

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

spec/logger.spec.ts

+44
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,50 @@ describe("logger", () => {
118118
});
119119
});
120120

121+
it("should not detect duplicate object as circular", () => {
122+
const obj: any = { a: "foo" };
123+
const entry: logger.LogEntry = {
124+
severity: "ERROR",
125+
message: "testing circular",
126+
a: obj,
127+
b: obj,
128+
};
129+
logger.write(entry);
130+
expectStderr({
131+
severity: "ERROR",
132+
message: "testing circular",
133+
a: { a: "foo" },
134+
b: { a: "foo" },
135+
});
136+
});
137+
138+
it("should not detect duplicate object in array as circular", () => {
139+
const obj: any = { a: "foo" };
140+
const arr: any = [
141+
{ a: obj, b: obj },
142+
{ a: obj, b: obj },
143+
];
144+
const entry: logger.LogEntry = {
145+
severity: "ERROR",
146+
message: "testing circular",
147+
a: arr,
148+
b: arr,
149+
};
150+
logger.write(entry);
151+
expectStderr({
152+
severity: "ERROR",
153+
message: "testing circular",
154+
a: [
155+
{ a: { a: "foo" }, b: { a: "foo" } },
156+
{ a: { a: "foo" }, b: { a: "foo" } },
157+
],
158+
b: [
159+
{ a: { a: "foo" }, b: { a: "foo" } },
160+
{ a: { a: "foo" }, b: { a: "foo" } },
161+
],
162+
});
163+
});
164+
121165
it("should not break on objects that override toJSON", () => {
122166
const obj: any = { a: new Date("August 26, 1994 12:24:00Z") };
123167

src/logger/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function removeCircular(obj: any, refs: any[] = []): any {
7878
returnObj[k] = removeCircular(obj[k], refs);
7979
}
8080
}
81+
refs.pop();
8182
return returnObj;
8283
}
8384

0 commit comments

Comments
 (0)