-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"TypeError: Converting circular structure to JSON" while using custom winston logger service #488
Comments
Possible solutions would be:
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key: any, value: object | null) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
...
this.logger.debug(`Configured HTTPServer Options: ${JSON.stringify(options, getCircularReplacer())}`);
...
import { stringify } from 'flatted';
...
this.logger.debug(`Configured HTTPServer Options: ${stringify(options)}`);
... |
Nice find, @HCarnegie! Another option could be to skip stringify-ing JSON.stringify( that.person, function( key, value) {
if( key == 'logger') { return logger.level; }
else {return value;}
}) |
Yes this could be a solution to avoid the error on logging the options, with the nice side effect not printing out the whole logger object. But we are facing the same issue at logging actor method calls, if a circular object is passed as an argument to the actor method. Even if no custom winston logger is configured for the DaprServer Object: As an example I passed a circular object to dapr actor method. The actor interface: interface IDemoCircularOpject {
circ?: IDemoCircularOpject;
}
interface IDemoActor {
test(circ: IDemoCircularOpject): void;
} The actor method call: ...
this.actorBuilder = new ActorProxyBuilder<IDemoActor>(
DemoActor,
dapr.client
);
const actor = this.actorBuilder.build(ActorId.createRandomId());
const circObj: IDemoCircularOpject = {};
circObj.circ = circObj;
actor.test(circObj); It will raises the following error - (similar to the one in my first comment - but occurs on another code path ):
|
The problem is that JSON does not accept circular references. This data gets serialized to be transported over the HTTP request. If it's indeed circular, it should throw an error IMO because there is no actual representation of this over JSON. If we try to handle this on our end and say use something like |
That makes sense. Thanks for pointing this out. Is there a way that actor objects could have methods which are not exposed to HTTP Server? Just methods only accessible for local code? E.g. to inject complex objects or functions? |
My two cents:
For your last question, could you make a separate issue for this please? "Allow private methods on actors that cannot be invoked" -> e.g., if If you are open to give it a shot, it would be in this method: https://github.com/dapr/js-sdk/blob/main/src/actors/runtime/ActorManager.ts#L132 which is responsible for checking if the method exists or not. Theoretically it could be a simple as adding a check that states "if string starts with |
As of v3.3.1, this bug is still occurring and simply preventing the use of a CustomLogger in a DaprServer. |
Expected Behavior
Using a custom winston logger service for the DaprServer object, should not cause an error.
Actual Behavior
Following the instruction of the sdk docs to use a custom winston logger service for the DaprServer object, it's going to raise an exception as soon as the DaprServer object is instantiated.
Steps to Reproduce the Problem
using package "@dapr/dapr": "^3.0.0"
I can reproduce the exception by adopting following steps to the actor-parking-sensor example:
passing the logger to the clientOptions or to serverOptions --> fails:
passing the logger only to the client constructor --> works fine:
The winston logger is a circular structured object and the HTTPServer constructor serializes the options on the constructor:
this.logger.debug(
Configured HTTPServer Options: ${JSON.stringify(options)}
);The same behavior can be reproduced when such an object is passed to any actor method. cause the arguments are serialized as well.
The text was updated successfully, but these errors were encountered: