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 #442

Closed
codetheweb opened this issue Mar 29, 2021 · 4 comments
Closed

TypeError: Converting circular structure to JSON #442

codetheweb opened this issue Mar 29, 2021 · 4 comments

Comments

@codetheweb
Copy link

I recently have been seeing a large increase in errors like this:

Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at processTicksAndRejections (node:internal/process/task_queues:94:5)
-- | -- | -- | --
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at runMicrotasks (<anonymous>)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at /usr/app/node_modules/bullmq/dist/classes/master.js:91:27
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at bound  (node:internal/util:311:12)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at new Promise (<anonymous>)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at node:internal/util:325:7
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at process.target.send (node:internal/child_process:722:19)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at process.target._send (node:internal/child_process:822:17)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at writeChannelMessage (node:internal/child_process/serialization:120:20)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | at stringify (<anonymous>)
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | --- property 'request' closes the circle
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | \|     property 'errored' -> object with constructor 'Object'
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | \|     property '_readableState' -> object with constructor 'ReadableState'
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | --> starting at object with constructor 'Request'
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | TypeError: Converting circular structure to JSON
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | ^
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | throw err;
  | Mar 29 10:45:54.487 | maxkvm-42196.local | backend | /usr/app/node_modules/bullmq/dist/classes/master.js:114

It's throwing on this line:

throw err;

I believe the root cause is an error from Got. Would it be possible to add some kind of check here so circular structures in errors don't cause Bull to crash?

@manast
Copy link
Contributor

manast commented Mar 29, 2021

Do you have a suggestion on how to implement this? as I understand, this happens because some unhandled exception in user code, it is mostly informing you that you have some unhandled error somewhere.

@codetheweb
Copy link
Author

Maybe attempt to do JSON.stringify(err) and if that throws then it's circular?

As long as it doesn't have any impact on Bull's operation it's not a big deal, but it would be nice to have a more user-friendly error.

@manast
Copy link
Contributor

manast commented Mar 29, 2021

If you are doing an operation that can throw an exception then you should handle that exception, like wrapping it in a try/catch statement. BullMQ wraps your processor in a try/catch already, so topmost exceptions are caught and results in the job failing. My guess is that you are calling that stringify in some callback deeper down the stack, then there is nothing we can do other than what we are already doing, i.e. bring to your attention that you have an unhandled exception somewhere in your code.

@codetheweb
Copy link
Author

Ah you're probably right, thank you.

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

2 participants