Skip to content

TypeError: Converting circular structure to JSON #10

@FreePhoenix888

Description

@FreePhoenix888

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions