I’m seeing this in the logs for one of our production environments:
link_key: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'update_val' -> object with constructor 'func'
--- property 'func_globals' closes the circle
There is nothing else in this browser session (no login, etc.). This has popped up a few times. These properties are not used in our code so I’m not convinced that it is our code running here.
Note: We are running in our own instance of Anvil for Enterprise so they can’t look at it directly.
Has anyone seen anything like this? Could this be something hitting an anvil endpoint with bad json?
To the best of my knowledge, JSON can’t encode circular structures in the first place.
Let’s have a closer look at the error message.
(emphasis mine).
From first principles, it looks like some code is trying to convert to JSON an object that, indirectly, contains itself (this is the “circular structure”). Which structure that is, or how it got that way, I have no idea. (But perhaps a real Anvilista will!)
JSON doesn’t support encoding such structures, nor do most hierarchical data formats. If code didn’t check for those structures, you’d get a JSON string of ever-increasing length, until something ran out of memory trying to keep track of where it left off.
Ah yes! Of course you are right that it is trying to convert to JSON (so the idea of a json payload is nonsensical). Perhaps some payload that says it is json but isn’t? Not really sure what might cause this.
It is very odd because it is a browser session without any other actions, which makes me think that something external is hitting it and the anvil runtime is throwing this.
A little more information I dug up (with help from ChatGPT):
That error message is JavaScript (or Node.js) — specifically from JSON.stringify when it tries to serialize an object with a circular reference.
The wording “Converting circular structure to JSON” is exactly what V8 (the JS engine in Chrome and Node) throws.
The arrow → starting at object with constructor ‘Object’ and the — property ‘func_globals’ closes the circle is Node’s enhanced formatting that shows you the reference loop path.
The problem happens when JSON.stringify encounters an object that references itself (directly or indirectly), which JSON can’t represent.