Skip to content

Unable to log circular objects with functions #437

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

Closed
marvinhagemeister opened this issue Aug 25, 2020 · 3 comments
Closed

Unable to log circular objects with functions #437

marvinhagemeister opened this issue Aug 25, 2020 · 3 comments

Comments

@marvinhagemeister
Copy link
Contributor

Logging an object with a circular reference works for as long as no property points to a function.

Without any function it works fine:

const a = { type: null, foo: 123 }
a.foo = a;
console.log(a);

...but when a function is present it fails.

const Foo = () => null;
const obj = { type: Foo, foo: null };
obj.foo = obj;
console.log(obj);

Error message:

Error while collecting browser logs: Evaluation failed: TypeError: Converting circular structure to JSON
          --> starting at object with constructor 'Window'
          --- property 'self' closes the circle
          at JSON.stringify (<anonymous>)
          at Object.serialize (<anonymous>:103:17)
          at __puppeteer_evaluation_script__:2:47
@LarsDenBakker
Copy link
Member

This one is pretty interesting. We handle circular references, but to serialize functions we actually create a new object with some information about the function. This way we created a new circular reference which wasn't handled properly.

It's fixed in @web/[email protected]

@marvinhagemeister
Copy link
Contributor Author

Woa that was quick!! 🙌

@bennypowers
Copy link
Member

bennypowers commented Nov 4, 2020

Getting

TypeError","message":"Converting circular structure to JSON

in some test files

at

export async function sendMessage(message) {
  if (!message.type) {
    throw new Error('Missing message type');
  }
  await webSocketOpened;
  webSocket.send(JSON.stringify(message));
}

webSocket.send(JSON.stringify(message));

We should safe-stringify there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants