You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When I pass an error object which has a circular structure to logger.info or any other logging method, I get the following error:
TypeError: Converting circular structure to JSON
To Reproduce
Execute the following code:
import{Logger}from'tslog';constlogger=newLogger();constrequest={url: 'http://example.com/does-not-exist',originalRequest: {}};request.originalRequest=request;consterror=newError('Failed to fetch the resource');error.request=request;logger.warn('The request failed',error);
To see this happening in a more realistic context, install got and run the following code:
import{Logger}from'tslog';importgotfrom'got';constlogger=newLogger();asyncfunctiongetResponse(){try{constresponse=awaitgot.get('http://example.com/does-not-exist');returnresponse;}catch(error){logger.warn('Failed to fetch the data',error);}};getResponse();
Expected behavior tslog stringifies the error object in such a way that it does not throw an error.
Screenshots
Output from the 2nd example above:
(node:15937) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property '_httpMessage' -> object with constructor 'ClientRequest'
--- property 'socket' closes the circle
at JSON.stringify (<anonymous>)
at Logger._buildErrorObject (/tmp/tmp.5tNebHIiKR/node_modules/tslog/src/index.ts:466:55)
at /tmp/tmp.5tNebHIiKR/node_modules/tslog/src/index.ts:432:16
at Array.forEach (<anonymous>)
at Logger._buildLogObject (/tmp/tmp.5tNebHIiKR/node_modules/tslog/src/index.ts:429:28)
at Logger._handleLog (/tmp/tmp.5tNebHIiKR/node_modules/tslog/src/index.ts:353:40)
at Logger.warn (/tmp/tmp.5tNebHIiKR/node_modules/tslog/src/index.ts:298:28)
at getResponse (/tmp/tmp.5tNebHIiKR/bug.ts:11:12)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Additional context
N/a
Node.js Version
v12.18.2
OS incl. Version
Linux Mint 19.1
The text was updated successfully, but these errors were encountered:
Thank you very much. Apparently, Error objects were treated differently, than other JS objects. I have solved this issue and plan to release a new version today.
Describe the bug
When I pass an error object which has a circular structure to
logger.info
or any other logging method, I get the following error:To Reproduce
Execute the following code:
To see this happening in a more realistic context, install
got
and run the following code:Expected behavior
tslog
stringifies the error object in such a way that it does not throw an error.Screenshots
Output from the 2nd example above:
Additional context
N/a
Node.js Version
v12.18.2
OS incl. Version
Linux Mint 19.1
The text was updated successfully, but these errors were encountered: