Cannot convert Circular structure to JSON



  • My script has stopped working due to a continuous "Cannot convert Circular structure to JSON" error.

     

    I commented out my entire main file (from line 0 to EOF) to try to get the error to stop, but to no avail.  This started last night with no code changes and appears to have been going for most of the night as I lost 3 levels on my 2 controllers.

    What changed?



  • it sounds like you put a recursive/circular reference somewhere in Memory. Try wiping out your Memory from the client?



  • Thanks for that pointer.  Looks like the issue was a RoomPosition object I was storing in memory.

     

    Any chance we could get a stack trace for this error?


  • Culture

    Unfortunately a stack won't help you.

    What's happening is that at some point you're assigning a value to memory that can't run through the JSON dump file. This stays in your Memory object through your whole tick. Once your tick finishes the code attempts to do a JSON.stringify on the Memory object and that's when it fails. So if you had a stack trace it wouldn't show you where you made the bad assignment, it would show a stack trace to that JSON.stringify call.



  • A stack trace would have shown that it was failing while trying to stringify memory rather than a console.log a circular reference though (which I've done before and had a similarly difficult time tracking down).

     

    Errors like this should always provide a stack trace to help point to where the error is (whether it's bad stored data, or a bad log).