unsafe stringify and JSON circular structure
nitzan-blink opened this issue · 0 comments
nitzan-blink commented
Hi,
if I pass an axios error object to the transport's .error()
function, the logger crashes with the following exception:
2024-05-05 09:59:11.394 Error: app logged out: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'httpAgent' -> object with constructor 'Agent'
| property 'sockets' -> object with constructor 'Object'
| ...
| property 'errored' -> object with constructor 'Object'
--- property 'config' closes the circle
2024-05-05 09:59:11.397 TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'httpAgent' -> object with constructor 'Agent'
| property 'sockets' -> object with constructor 'Object'
| ...
| property 'errored' -> object with constructor 'Object'
--- property 'config' closes the circle
at JSON.stringify (<anonymous>)
at LogstashTransport.log (/app/node_modules/.pnpm/winston-logstash@1.2.1_winston@3.13.0/node_modules/winston-logstash/lib/winston-logstash-latest.js:34:27)
at LogstashTransport._write (/app/node_modules/.pnpm/winston-transport@4.5.0/node_modules/winston-transport/index.js:82:19)
at doWrite (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:390:139)
at writeOrBuffer (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:381:5)
at Writable.write (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:302:11)
at DerivedLogger.ondata (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:629:20)
at DerivedLogger.emit (node:events:529:35)
at addChunk (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:279:12)
at readableAddChunk (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:262:11)
a related issue is: winstonjs/winston#1946
where it was suggested that fast-safe-stringify
should be used instead of JSON.stringify()
.
in the code I see several refernces to stringify
libs, but they are all in the test bench.