Skip to content
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 #10

Open
FreePhoenix888 opened this issue Jul 17, 2023 · 2 comments
Open

TypeError: Converting circular structure to JSON #10

FreePhoenix888 opened this issue Jul 17, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@FreePhoenix888
Copy link
Member

Describe the bug

Handler with code

async (arg) => {
  return arg
}

Rejects with error:

{
  "stack": "TypeError: Converting circular structure to JSON\n    --> starting at object with constructor 'Object'\n    |     property 'Provider' -> object with constructor 'Object'\n    --- property '_context' closes the circle\n    at JSON.stringify (<anonymous>)\n    at stringify (/node_modules/express/lib/response.js:1150:12)\n    at ServerResponse.json (/node_modules/express/lib/response.js:271:14)\n    at file:///index.js:77:13\n    at Generator.next (<anonymous>)\n    at fulfilled (file:///index.js:4:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
  "message": "Converting circular structure to JSON\n    --> starting at object with constructor 'Object'\n    |     property 'Provider' -> object with constructor 'Object'\n    --- property '_context' closes the circle"
}

Workaround:
Use util.inspect:

async (arg) => {
  const util = await import('util')
  return util.inspect(arg, {depth: 15})
}

Expected Behavior

Handler to return that json

Current Behavior

Handler rejects with error

Steps to reproduce

No response

Environment

No response

@FreePhoenix888 FreePhoenix888 added the bug Something isn't working label Jul 17, 2023
@FreePhoenix888
Copy link
Member Author

https://stackoverflow.com/questions/10392293/stringify-convert-to-json-a-javascript-object-with-circular-reference

I have already wrote workaround with util.inspect but should not provider do it itself for returnied value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants